hibernate/hibernate-orm · error · AssertionFailure
getGeneratedKeys() support is not enabled
Error message
getGeneratedKeys() support is not enabled
What it means
Same invariant as the MutationStatementPreparer variant: StatementPreparerImpl.checkAutoGeneratedKeysSupportEnabled() throws an AssertionFailure when a PreparedStatement is requested with PreparedStatement.RETURN_GENERATED_KEYS but the SessionFactory setting hibernate.jdbc.use_get_generated_keys is false. It fires from the classic statement-preparer path, e.g. identity inserts and getGeneratedKeys-style retrieval.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java:106
public CallableStatement prepareCallableStatement(String sql) {
jdbcCoordinator.executeBatch();
return (CallableStatement) prepareStatement( sql, true );
}
private StatementPreparationTemplate buildPreparedStatementPreparationTemplate(String sql, final boolean isCallable) {
return new StatementPreparationTemplate( sql ) {
@Override
protected PreparedStatement doPrepare() throws SQLException {
return isCallable
? connection().prepareCall( sql )
: connection().prepareStatement( sql );
}
};
}
private void checkAutoGeneratedKeysSupportEnabled() {
if ( ! settings().isGetGeneratedKeysEnabled() ) {
throw new AssertionFailure( "getGeneratedKeys() support is not enabled" );
}
}
@Override
public PreparedStatement prepareStatement(String sql, final int autoGeneratedKeys) {
if ( autoGeneratedKeys == PreparedStatement.RETURN_GENERATED_KEYS ) {
checkAutoGeneratedKeysSupportEnabled();
}
jdbcCoordinator.executeBatch();
return new StatementPreparationTemplate( sql ) {
public PreparedStatement doPrepare() throws SQLException {
return connection().prepareStatement( sql, autoGeneratedKeys );
}
}.prepareStatement();
}
@Override
public PreparedStatement prepareStatement(String sql, final String[] columnNames) {View on GitHub (pinned to fad1729dce)
Solutions
- Remove hibernate.jdbc.use_get_generated_keys=false or set it to true (the default is auto-detected from the dialect)
- If the driver really cannot do getGeneratedKeys, switch entities to SEQUENCE/TABLE/UUID id generation
- Search the whole config surface (persistence.xml, properties files, builders, environment variables) for the override
Example fix
# before hibernate.jdbc.use_get_generated_keys=false # after hibernate.jdbc.use_get_generated_keys=true
Defensive patterns
Strategy: validation
Validate before calling
// fail fast at boot if the setting conflicts with identity mappings
boolean generatedKeysOff = Boolean.parseBoolean(
props.getProperty("hibernate.jdbc.use_get_generated_keys", "true"));
if (!generatedKeysOff || usesIdentity(entities)) { /* ok */ }
else throw new IllegalStateException("generated keys disabled but IDENTITY used"); Prevention
- Default hibernate.jdbc.use_get_generated_keys to auto/true
- When a driver lacks getGeneratedKeys, use SEQUENCE or UUID ids
- Grep config files for legacy 'use_get_generated_keys=false' during upgrades
When it happens
Trigger: prepareStatement(sql, Statement.RETURN_GENERATED_KEYS) is invoked (identity id generation, native strategy resolving to identity) while hibernate.jdbc.use_get_generated_keys=false was configured explicitly or the resolved setting is false.
Common situations: Legacy configuration files that disabled generated keys for old drivers/batch tuning; programmatic settings overrides; copying persistence.xml between projects with different id strategies.
Related errors
- getGeneratedKeys() support is not enabled
- The database returned no natively generated values : {}
- Configuration property hibernate.jdbc.time_zone value [{}] i
- Default resolver threw exception
- ${getClass().getName()} does not support selecting the last
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/89283a70bb4c31aa.
Report an issue: GitHub.