{"record":{"id":"e96ca0d033532970","repo":"hibernate/hibernate-orm","slug":"database-doesn-t-support-extracting-all-foreign-ke","errorCode":null,"errorMessage":"Database doesn't support extracting all foreign keys at once","messagePattern":"Database doesn't support extracting all foreign 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":1497,"sourceCode":"\t\t\t}\n\t\t}\n\t\tcatch (SQLException e) {\n\t\t\tthrow convertSQLException( e,\n\t\t\t\t\t\"Error accessing column metadata: \"\n\t\t\t\t\t\t\t+ tableInformation.getName() );\n\t\t}\n\n\t\tfinal List<ForeignKeyInformation> foreignKeys = new ArrayList<>( builders.size() );\n\t\tfor ( var foreignKeyBuilder : builders.values() ) {\n\t\t\tforeignKeys.add( foreignKeyBuilder.build() );\n\t\t}\n\t\treturn foreignKeys;\n\t}\n\n\t@Override\n\tpublic NameSpaceForeignKeysInformation getForeignKeys(Identifier catalog, Identifier schema) {\n\t\tif ( !supportsBulkForeignKeyRetrieval() ) {\n\t\t\tthrow new UnsupportedOperationException( \"Database doesn't support extracting all foreign keys at once\" );\n\t\t}\n\t\telse {\n\t\t\ttry {\n\t\t\t\treturn processImportedKeysResultSet(\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\tnull,\n\t\t\t\t\t\tthis::extractNameSpaceForeignKeysInformation\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 foreign key information 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":1479,"sourceCodeEnd":1515,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/AbstractInformationExtractorImpl.java#L1479-L1515","documentation":"InformationExtractor#getForeignKeys(Identifier, Identifier) is the namespace-wide (bulk) foreign-key retrieval entry point, guarded by supportsBulkForeignKeyRetrieval(). When the active extractor/dialect cannot fetch all foreign keys in one query, calling it throws UnsupportedOperationException — foreign keys must then be fetched table by table.","triggerScenarios":"Calling extractor.getForeignKeys(catalog, schema) for a whole namespace while the active extractor reports supportsBulkForeignKeyRetrieval() == false — custom dialect/extractor overrides, or tooling performing namespace-wide FK scans on such setups.","commonSituations":"Custom InformationExtractor implementations; reverse-engineering or schema-diff tools iterating whole schemas; grouped schema management on databases without a usable bulk imported-keys query.","solutions":["Fetch per table: getTable(catalog, schema, table).getForeignKeys() instead of the namespace-wide call.","If you own the extractor, implement the bulk foreign-key path and make supportsBulkForeignKeyRetrieval() return true.","Catch UnsupportedOperationException and degrade to per-table iteration."],"exampleFix":"// before\nNameSpaceForeignKeysInformation all = extractor.getForeignKeys(catalog, schema); // may throw\n\n// after\nNameSpaceForeignKeysInformation all;\ntry {\n    all = extractor.getForeignKeys(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.getForeignKeys();\n    }\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"NameSpaceForeignKeysInformation all;\ntry {\n    all = extractor.getForeignKeys(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.getForeignKeys();\n    }\n}","preventionTips":["Prefer per-table foreign-key retrieval when supporting multiple databases.","Document bulk-capability overrides in custom dialects/extraction contexts.","Wrap namespace-wide extraction behind a helper that degrades gracefully."],"tags":["hibernate","schema-extraction","foreign-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"}