hibernate/hibernate-orm · error · MappingException
${getClass().getName()} does not support identity key genera
Error message
${getClass().getName()} does not support identity key generation What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/dialect/identity/IdentityColumnSupportImpl.java:41
@Override
public boolean supportsInsertSelectIdentity() {
return false;
}
@Override
public boolean hasDataTypeInIdentityColumn() {
return true;
}
@Override
public String appendIdentitySelectToInsert(String identityColumnName, String insertString) {
return insertString;
}
@Override
public String getIdentitySelectString(String table, String column, int type) throws MappingException {
throw new MappingException( getClass().getName() + " does not support identity key generation" );
}
@Override
public String getIdentityColumnString(int type) throws MappingException {
throw new MappingException( getClass().getName() + " does not support identity key generation" );
}
@Override
public String getIdentityInsertString() {
return null;
}
@Override
public GetGeneratedKeysDelegate buildGetGeneratedKeysDelegate(EntityPersister persister) {
return new GetGeneratedKeysDelegate( persister, true, EventType.INSERT );
}
}
View on GitHub (pinned to fad1729dce)
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
Example fix
// before @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; // after (database/dialect without identity support) @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id;
Defensive patterns
Strategy: validation
Validate before calling
// Fail fast before opening a session if the dialect cannot do identity
Dialect dialect = sessionFactory.getJdbcServices().getDialect();
if (!dialect.getIdentityColumnSupport().supportsIdentityColumns() && usesIdentityGeneration(metadata)) {
throw new IllegalStateException("Dialect " + dialect.getClass().getName()
+ " does not support identity key generation - use SEQUENCE or UUID");
} Try / catch
try {
sessionFactory = configuration.buildSessionFactory();
}
catch (MappingException e) {
if (e.getMessage().endsWith("does not support identity key generation")) {
throw new IllegalStateException("Change @GeneratedValue(strategy = IDENTITY) to SEQUENCE/UUID for this database", e);
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- dialect does not support sequences
- Null id generated for entity '%s'
- Dialect does not support structured array types: ${dialectCl
- Database does not support user-defined types (remove '@Struc
- unknown type: {sqlTypeCode}
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/a22f2e5071feec68.
Report an issue: GitHub.