hibernate/hibernate-orm · error · SchemaExtractionException
Primary Key information was missing for KEY_SEQ = %s
Error message
Primary Key information was missing for KEY_SEQ = %s
What it means
Primary-key rows are slotted into a column list indexed by KEY_SEQ (column position minus one). After the resultset is consumed, any remaining null slot means no row supplied that ordinal — the driver reported non-contiguous sequence numbers — and Hibernate throws SchemaExtractionException naming the missing KEY_SEQ rather than producing a primary key with a hole in it.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/AbstractInformationExtractorImpl.java:971
final int columnPosition = resultSet.getInt( getResultSetColumnPositionColumn() );
final int index = columnPosition - 1;
// Fill up the array list with nulls up to the desired index, because some JDBC drivers don't return results ordered by column position
while ( columns.size() <= index ) {
columns.add( null );
}
final Identifier columnIdentifier =
toIdentifier( resultSet.getString( getResultSetColumnNameLabel() ) );
columns.set( index, tableInformation.getColumn( columnIdentifier ) );
}
if ( firstPass ) {
// we did not find any results (no pk)
return null;
}
else {
// validate column list is properly contiguous
for ( int i = 0; i < columns.size(); i++ ) {
if ( columns.get( i ) == null ) {
throw new SchemaExtractionException( "Primary Key information was missing for KEY_SEQ = " + ( i+1) );
}
}
// build the return
return new PrimaryKeyInformationImpl( primaryKeyIdentifier, columns );
}
}
@Override
public NameSpacePrimaryKeysInformation getPrimaryKeys(Identifier catalog, Identifier schema) {
if ( !supportsBulkPrimaryKeyRetrieval() ) {
throw new UnsupportedOperationException( "Database doesn't support extracting all primary keys at once" );
}
else {
try {
return processPrimaryKeysResultSet(
catalog == null ? "" : catalog.getText(),
schema == null ? "" : schema.getText(),
(String) null,View on GitHub (pinned to fad1729dce)
Solutions
- Switch to a JDBC driver version that follows the KEY_SEQ contract (1-based, contiguous, one row per PK column).
- Avoid the broken path when possible: use hbm2ddl none, or manage the schema with tooling that does not need PK extraction on that driver.
- Report it to the Hibernate tracker (HHH) with the driver name and version — extraction quirks get dialect-specific workarounds.
Defensive patterns
Strategy: try-catch
Try / catch
try {
schemaValidator.validate(metadata, databaseModel);
} catch (SchemaExtractionException e) {
if (e.getMessage() != null && e.getMessage().contains("KEY_SEQ")) {
// driver returned non-contiguous PK positions — switch or upgrade the driver
}
throw e;
} Prevention
- Avoid niche drivers for schema management; use the vendor's certified driver.
- Smoke-test hbm2ddl validate in CI against the production database engine.
- Report KEY_SEQ violations to the driver vendor with a metadata dump.
When it happens
Trigger: A driver that returns KEY_SEQ starting at zero, with gaps, or with duplicate positions; or rows whose position column could not be read correctly, leaving an index uninitialized while a later row enlarged the list.
Common situations: Niche or third-party drivers (SQLite wrappers, legacy SQL Server drivers, pool/proxy layers rewriting metadata) violating the JDBC KEY_SEQ contract; behavior appearing after a driver upgrade.
Related errors
- Encountered primary keys differing name on table %s
- Database doesn't support extracting all primary keys at once
- Could not locate table information for %s
- Primary Key information was missing for key [%s] on table [%
- No add primary key syntax supported by SQLiteDialect
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/0cedeb6aea5d30cb.
Report an issue: GitHub.