{"record":{"id":"ece11cdd56d4aeee","repo":"hibernate/hibernate-orm","slug":"sql-strings-added-more-than-once-for-ece11c","errorCode":null,"errorMessage":"SQL strings added more than once for: ","messagePattern":"SQL strings added more than once for: ","errorType":"exception","errorClass":"SchemaManagementException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java","lineNumber":488,"sourceCode":"\t\t\t\t\t\t&& schemaFilter.includeTable( table )\n\t\t\t\t\t\t&& inclusionFilter.matches( table ) ) {\n\t\t\t\t\tfor ( var foreignKey : table.getForeignKeyCollection() ) {\n\t\t\t\t\t\tapplySqlStrings(\n\t\t\t\t\t\t\t\tdialect.getForeignKeyExporter().getSqlDropStrings( foreignKey, metadata, context ),\n\t\t\t\t\t\t\t\tformatter,\n\t\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\t\ttargets\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static void checkExportIdentifier(Exportable exportable, Set<String> exportIdentifiers) {\n\t\tfinal String exportIdentifier = exportable.getExportIdentifier();\n\t\tif ( exportIdentifiers.contains( exportIdentifier ) ) {\n\t\t\tthrow new SchemaManagementException( \"SQL strings added more than once for: \" + exportIdentifier );\n\t\t}\n\t\texportIdentifiers.add( exportIdentifier );\n\t}\n\n\t@Override\n\tpublic DelayedDropAction buildDelayedAction(\n\t\t\tMetadata metadata,\n\t\t\tExecutionOptions options,\n\t\t\tContributableMatcher inclusionFilter,\n\t\t\tSourceDescriptor sourceDescriptor) {\n\t\tfinal var target = new JournalingGenerationTarget();\n\t\tfinal var dialect = tool.getServiceRegistry().requireService( JdbcEnvironment.class ).getDialect();\n\t\tdoDrop( metadata, options, inclusionFilter, dialect, sourceDescriptor, target );\n\t\treturn new DelayedDropActionImpl( target.commands, tool.getCustomDatabaseGenerationTarget() );\n\t}\n\n\t/**\n\t * For tests","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java#L470-L506","documentation":"The drop path applies the same one-SQL-per-exportable invariant as creation: while building DROP statements SchemaDropperImpl records each Exportable's export identifier, and a second occurrence of the same identifier throws this SchemaManagementException. The object named in the message is registered twice in the Metadata being dropped, so the mapping is ambiguous, not the database.","triggerScenarios":"Running drop, drop-and-create, or drop-only schema management (SchemaExport.drop, hbm2ddl drop/create-drop teardown) over Metadata that maps the same table/sequence/UDT/auxiliary object twice. Same root causes as the create-side guard: duplicate entity table names, doubly-registered mapping classes, or duplicated auxiliary database objects.","commonSituations":"Test profiles using drop-and-create that hit a refactoring artifact (two entities on one table); the same hbm.xml resource included via two classpath entries; @AuxiliaryDatabaseObject present in both an annotated class and an XML mapping; multi-module projects merging overlapping MetadataSources.","solutions":["Grep mappings for the identifier in the message and de-duplicate the registration so the object is mapped once.","If the overlap is intentional (e.g., view and table sharing a name), rename one object so the export identifiers differ.","Check MetadataSources construction for addResource/addAnnotatedClass calls that resolve to the same mapping, and persistence.xml mapping-file entries for duplicates."],"exampleFix":"// before\nMetadataSources sources = new MetadataSources(registry)\n        .addAnnotatedClass(Order.class)\n        .addResource(\"/mappings/Order.hbm.xml\"); // same class mapped twice\n\n// after\nMetadataSources sources = new MetadataSources(registry)\n        .addAnnotatedClass(Order.class);","handlingStrategy":"validation","validationCode":"// before dropping, assert each mapped table name is registered exactly once\nSet<String> names = new HashSet<>();\nmetadata.collectTableMappings(s -> names.add(s) == false, ...); // pseudo: collect export identifiers\nif (names.size() != expectedUniqueCount) { /* refuse to drop, report duplicates */ }","typeGuard":null,"tryCatchPattern":"try {\n    schemaManagementTool.getSchemaDropper(settings).doDrop(metadata, false, source, options, targetDescriptor);\n} catch (SchemaManagementException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"SQL strings added more than once for:\")) {\n        String exportable = e.getMessage().substring(e.getMessage().lastIndexOf(' ') + 1);\n        // de-duplicate the mapping for `exportable` before re-running the drop\n    } else { throw e; }\n}","preventionTips":["Run a create-export (STDOUT) against new mappings in CI — it catches duplicates before drop/create-drop ever runs.","Keep mapping registration centralized; avoid merging MetadataSources from overlapping modules.","Audit auxiliary database objects when both XML and annotations are in play."],"tags":["hibernate","schema-generation","mapping","duplicate","ddl","drop-schema"],"backgroundTag":"duplicate-schema-object-mapping","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}