{"record":{"id":"34d6638a4d698419","repo":"hibernate/hibernate-orm","slug":"database-doesn-t-support-extracting-all-primary-ke","errorCode":null,"errorMessage":"Database doesn't support extracting all primary keys at once","messagePattern":"Database doesn't support extracting all primary keys at once","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/AbstractInformationExtractorImpl.java","lineNumber":982,"sourceCode":"\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,\n\t\t\t\t\t\tthis::extractNameSpacePrimaryKeysInformation\n\t\t\t\t);\n\t\t\t}\n\t\t\tcatch (SQLException e) {\n\t\t\t\tthrow convertSQLException( e,\n\t\t\t\t\t\t\"Error while reading primary key meta data for namespace \"\n\t\t\t\t\t\t+ new Namespace.Name( catalog, schema ) );\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":964,"sourceCodeEnd":1000,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/AbstractInformationExtractorImpl.java#L964-L1000","documentation":"InformationExtractor#getPrimaryKeys(Identifier, Identifier) is the namespace-wide (bulk) primary-key retrieval entry point, guarded by supportsBulkPrimaryKeyRetrieval(). When the active extractor/dialect cannot fetch all primary keys in a single query, calling it throws UnsupportedOperationException — the data must instead be requested table by table.","triggerScenarios":"Schema tooling or user code calling getPrimaryKeys(catalog, schema) for a whole namespace while the active dialect/extractor reports supportsBulkPrimaryKeyRetrieval() == false (custom dialects overriding bulk support, or databases without a grouped PK metadata query).","commonSituations":"Custom InformationExtractor/Dialect implementations; namespace-wide schema management (grouped extraction) run against databases whose bulk queries are unavailable; reverse-engineering tools iterating whole schemas.","solutions":["Use per-table extraction: getTable(catalog, schema, table).getPrimaryKey() instead of the namespace-wide call.","If you own the extractor/dialect, implement the bulk query path and make supportsBulkPrimaryKeyRetrieval() return true.","Catch UnsupportedOperationException and fall back to iterating tables individually."],"exampleFix":"// before\nNameSpacePrimaryKeysInformation all = extractor.getPrimaryKeys(catalog, schema); // may throw\n\n// after\nNameSpacePrimaryKeysInformation all;\ntry {\n    all = extractor.getPrimaryKeys(catalog, schema);\n} catch (UnsupportedOperationException e) {\n    all = null; // degrade to per-table retrieval\n    for (TableInformation t : extractor.getTables(catalog, schema, null)) {\n        t.getPrimaryKey();\n    }\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"NameSpacePrimaryKeysInformation all;\ntry {\n    all = extractor.getPrimaryKeys(catalog, schema);\n} catch (UnsupportedOperationException e) {\n    all = null; // bulk not supported — fall back to per-table retrieval\n    for (TableInformation t : extractor.getTables(catalog, schema, null)) {\n        t.getPrimaryKey();\n    }\n}","preventionTips":["Prefer per-table extraction APIs when targeting multiple databases.","Check supportsBulkPrimaryKeyRetrieval() (or document the dialect's bulk capabilities) before namespace-wide calls.","Wrap namespace-wide extraction behind a helper that degrades to per-table mode."],"tags":["hibernate","schema-extraction","primary-key","unsupported-operation","dialect"],"backgroundTag":"unsupported-bulk-metadata-extraction","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}