{"record":{"id":"a22f2e5071feec68","repo":"hibernate/hibernate-orm","slug":"getclass-getname-does-not-support-identity","errorCode":null,"errorMessage":"${getClass().getName()} does not support identity key generation","messagePattern":"(.+?) does not support identity key generation","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/dialect/identity/IdentityColumnSupportImpl.java","lineNumber":41,"sourceCode":"\n\t@Override\n\tpublic boolean supportsInsertSelectIdentity() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic boolean hasDataTypeInIdentityColumn() {\n\t\treturn true;\n\t}\n\n\t@Override\n\tpublic String appendIdentitySelectToInsert(String identityColumnName, String insertString) {\n\t\treturn insertString;\n\t}\n\n\t@Override\n\tpublic String getIdentitySelectString(String table, String column, int type) throws MappingException {\n\t\tthrow new MappingException( getClass().getName() + \" does not support identity key generation\" );\n\t}\n\n\t@Override\n\tpublic String getIdentityColumnString(int type) throws MappingException {\n\t\tthrow new MappingException( getClass().getName() + \" does not support identity key generation\" );\n\t}\n\n\t@Override\n\tpublic String getIdentityInsertString() {\n\t\treturn null;\n\t}\n\n\t@Override\n\tpublic GetGeneratedKeysDelegate buildGetGeneratedKeysDelegate(EntityPersister persister) {\n\t\treturn new GetGeneratedKeysDelegate( persister, true, EventType.INSERT );\n\t}\n}\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/identity/IdentityColumnSupportImpl.java#L23-L59","documentation":"IdentityColumnSupportImpl is the base implementation used by dialects that do not support IDENTITY key generation; its getIdentitySelectString unconditionally throws MappingException '<dialect class> does not support identity key generation'. Hibernate invokes it when it needs the SQL fragment that retrieves the just-generated identity value after an insert (for example when preparing the persister's post-insert identity extractor). The message names the concrete dialect class so you can see which dialect lacks the feature.","triggerScenarios":"An entity is mapped with @GeneratedValue(strategy = GenerationType.IDENTITY) while the active dialect's IdentityColumnSupport does not override getIdentitySelectString - e.g. a custom or Noop dialect, or one that only supports sequences. The exception typically appears at SessionFactory build time or on first insert when Hibernate asks for the identity select statement. Trigger also fires for hbm.xml <generator class=\"identity\"/> on such dialects.","commonSituations":"Running tests with an in-memory or custom dialect that lacks identity support; migrating an application from MySQL/Postgres (identity works) to a database whose dialect only supports sequences; setting hibernate.dialect explicitly to the wrong class for the target database.","solutions":["Switch the generator to SEQUENCE (or the dialect's native 'sequence' strategy) for databases without identity support","Remove the hardcoded hibernate.dialect and let Hibernate resolve the right dialect for your JDBC connection","If the database really does support identity (e.g. a newer version), upgrade Hibernate so its dialect knows about it, or extend the dialect to return a proper IdentityColumnSupport","For arbitrary key types, assign ids client-side (UUID generator) instead of relying on the database"],"exampleFix":"// before\n@Id\n@GeneratedValue(strategy = GenerationType.IDENTITY)\nprivate Long id;\n\n// after (database/dialect without identity support)\n@Id\n@GeneratedValue(strategy = GenerationType.SEQUENCE)\nprivate Long id;","handlingStrategy":"validation","validationCode":"// Fail fast before opening a session if the dialect cannot do identity\nDialect dialect = sessionFactory.getJdbcServices().getDialect();\nif (!dialect.getIdentityColumnSupport().supportsIdentityColumns() && usesIdentityGeneration(metadata)) {\n    throw new IllegalStateException(\"Dialect \" + dialect.getClass().getName()\n            + \" does not support identity key generation - use SEQUENCE or UUID\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    sessionFactory = configuration.buildSessionFactory();\n}\ncatch (MappingException e) {\n    if (e.getMessage().endsWith(\"does not support identity key generation\")) {\n        throw new IllegalStateException(\"Change @GeneratedValue(strategy = IDENTITY) to SEQUENCE/UUID for this database\", e);\n    }\n    throw e;\n}","preventionTips":["Do not hardcode hibernate.dialect; let Hibernate resolve it from the JDBC URL","Prefer SEQUENCE generators for portable mappings","Centralize id-generation policy in one place instead of per-entity IDENTITY defaults"],"tags":["hibernate","dialect","identity","mapping","sequence"],"backgroundTag":"identity-generation-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}