{"record":{"id":"0cedeb6aea5d30cb","repo":"hibernate/hibernate-orm","slug":"primary-key-information-was-missing-for-key-seq","errorCode":null,"errorMessage":"Primary Key information was missing for KEY_SEQ = %s","messagePattern":"Primary Key information was missing for KEY_SEQ = (.+?)","errorType":"exception","errorClass":"SchemaExtractionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/AbstractInformationExtractorImpl.java","lineNumber":971,"sourceCode":"\t\t\tfinal int columnPosition = resultSet.getInt( getResultSetColumnPositionColumn() );\n\t\t\tfinal int index = columnPosition - 1;\n\t\t\t// Fill up the array list with nulls up to the desired index, because some JDBC drivers don't return results ordered by column position\n\t\t\twhile ( columns.size() <= index ) {\n\t\t\t\tcolumns.add( null );\n\t\t\t}\n\t\t\tfinal Identifier columnIdentifier =\n\t\t\t\t\ttoIdentifier( resultSet.getString( getResultSetColumnNameLabel() ) );\n\t\t\tcolumns.set( index, tableInformation.getColumn( columnIdentifier ) );\n\t\t}\n\t\tif ( firstPass ) {\n\t\t\t// we did not find any results (no pk)\n\t\t\treturn null;\n\t\t}\n\t\telse {\n\t\t\t// validate column list is properly contiguous\n\t\t\tfor ( int i = 0; i < columns.size(); i++ ) {\n\t\t\t\tif ( columns.get( i ) == null ) {\n\t\t\t\t\tthrow new SchemaExtractionException( \"Primary Key information was missing for KEY_SEQ = \" + ( i+1) );\n\t\t\t\t}\n\t\t\t}\n\t\t\t// build the return\n\t\t\treturn new PrimaryKeyInformationImpl( primaryKeyIdentifier, columns );\n\t\t}\n\t}\n\n\t@Override\n\tpublic NameSpacePrimaryKeysInformation getPrimaryKeys(Identifier catalog, Identifier schema) {\n\t\tif ( !supportsBulkPrimaryKeyRetrieval() ) {\n\t\t\tthrow new UnsupportedOperationException( \"Database doesn't support extracting all primary keys at once\" );\n\t\t}\n\t\telse {\n\t\t\ttry {\n\t\t\t\treturn processPrimaryKeysResultSet(\n\t\t\t\t\t\tcatalog == null ? \"\" : catalog.getText(),\n\t\t\t\t\t\tschema == null ? \"\" : schema.getText(),\n\t\t\t\t\t\t(String) null,","sourceCodeStart":953,"sourceCodeEnd":989,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/AbstractInformationExtractorImpl.java#L953-L989","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    schemaValidator.validate(metadata, databaseModel);\n} catch (SchemaExtractionException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"KEY_SEQ\")) {\n        // driver returned non-contiguous PK positions — switch or upgrade the driver\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["hibernate","schema-extraction","primary-key","jdbc-driver","key-seq"],"backgroundTag":"inconsistent-primary-key-metadata","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}