{"record":{"id":"36d85afe00734898","repo":"hibernate/hibernate-orm","slug":"export-identifier-s-encountered-more-than-once","errorCode":null,"errorMessage":"Export identifier [%s] encountered more than once","messagePattern":"Export identifier \\[(.+?)\\] encountered more than once","errorType":"exception","errorClass":"SchemaManagementException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java","lineNumber":491,"sourceCode":"\n\tboolean equivalentForeignKeyExistsInDatabase(TableInformation tableInformation, String referencingColumn, String referencedTable) {\n\t\treturn StreamSupport.stream( tableInformation.getForeignKeys().spliterator(), false )\n\t\t\t\t.flatMap( foreignKeyInformation -> StreamSupport.stream( foreignKeyInformation.getColumnReferenceMappings().spliterator(), false ) )\n\t\t\t\t.anyMatch( columnReferenceMapping -> {\n\t\t\tfinal var referencingColumnMetadata = columnReferenceMapping.getReferencingColumnMetadata();\n\t\t\tfinal var referencedColumnMetadata = columnReferenceMapping.getReferencedColumnMetadata();\n\t\t\tfinal String existingReferencingColumn = referencingColumnMetadata.getColumnIdentifier().getText();\n\t\t\tfinal String existingReferencedTable =\n\t\t\t\t\treferencedColumnMetadata.getContainingTableInformation().getName().getTableName().getCanonicalName();\n\t\t\treturn referencingColumn.equalsIgnoreCase( existingReferencingColumn )\n\t\t\t\t&& referencedTable.equalsIgnoreCase( existingReferencedTable );\n\t\t} );\n\t}\n\n\tprotected 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(\n\t\t\t\t\tString.format(\"Export identifier [%s] encountered more than once\", exportIdentifier )\n\t\t\t);\n\t\t}\n\t\texportIdentifiers.add( exportIdentifier );\n\t}\n\n\tprotected static void applySqlStrings(\n\t\t\tboolean quiet,\n\t\t\tString[] sqlStrings,\n\t\t\tFormatter formatter,\n\t\t\tExecutionOptions options,\n\t\t\tGenerationTarget... targets) {\n\t\tif ( sqlStrings != null ) {\n\t\t\tfor ( String sql : sqlStrings ) {\n\t\t\t\tapplySqlString( quiet, sql, formatter, options, targets );\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java#L473-L509","documentation":"SchemaManagementException from AbstractSchemaMigrator.checkExportIdentifier: during schema migration, two exportable schema objects (tables, sequences) produced the same export identifier (typically schema.table or the sequence name). The migrator keeps a Set of identifiers so each object is migrated exactly once; a duplicate means the same database object is represented twice in the Metadata model.","triggerScenarios":"Running SchemaUpdate (hibernate.hbm2ddl.auto=update) when the mapped model contains the same object twice: two @Entity classes mapped to the same @Table name in the same schema, an entity registered twice in persistence.xml/hibernate.cfg.xml, a table mapped both by an entity and by a leftover hbm.xml or <join>, or two sequence definitions (@SequenceGenerator with the same sequenceName in different entities).","commonSituations":"Copy-pasted entity left behind in another package after a refactor; persistence.xml listing a class both explicitly and via auto-scan; the same jar duplicated on the classpath so mappings register twice; two modules mapping one legacy table; a name collision differing only in quoting/case.","solutions":["Take the identifier from the message and grep for it across @Table/@SequenceGenerator annotations and XML mappings to find the duplicate definitions.","Remove or rename the duplicate mapping (one owning entity per table; one generator per sequence name).","If two classes must read the same data, map a database view under a distinct name instead of the table twice.","Check the classpath for duplicated jars/classes and persistence.xml for double <class> entries."],"exampleFix":"// before: two entities mapped to the same table -> duplicate export identifier\n@Entity @Table(name = \"customer\")\npublic class Customer { ... }\n\n@Entity @Table(name = \"customer\")\npublic class Client { ... }\n\n// after: one owning entity; expose the second view via a mapped DB view\n@Entity @Table(name = \"customer\")\npublic class Customer { ... }\n\n@Entity @Table(name = \"client_view\") // CREATE VIEW client_view AS SELECT ...\npublic class Client { ... }","handlingStrategy":"validation","validationCode":"// Before SchemaUpdate, assert every exportable in the model has a unique export identifier\nSet<String> seen = new HashSet<>();\nmetadata.getDatabase().getNamespaces().forEach(ns -> {\n    ns.getTables().forEach(t -> {\n        if (!seen.add(t.getExportIdentifier())) {\n            throw new IllegalStateException(\"Duplicate export identifier: \" + t.getExportIdentifier());\n        }\n    });\n    ns.getSequences().forEach(s -> {\n        if (!seen.add(s.getExportIdentifier())) {\n            throw new IllegalStateException(\"Duplicate export identifier: \" + s.getExportIdentifier());\n        }\n    });\n});","typeGuard":null,"tryCatchPattern":"try {\n    new SchemaUpdate(metadata, registry).execute(EnumSet.of(TargetType.DATABASE), ...);\n} catch (SchemaManagementException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"encountered more than once\")) {\n        // grep the reported identifier across @Table/@SequenceGenerator and mapping XML to find the duplicate registration\n    }\n    throw e;\n}","preventionTips":["One owning entity per physical table; expose extra read models via database views with distinct names","Keep a single mapping source (annotations OR xml) and audit persistence.xml for duplicate <class> entries","Check for duplicated jars/classes on the classpath when entity scans register mappings twice"],"tags":["hibernate","schema-management","duplicate-mapping","entity-mapping","hbm2ddl"],"backgroundTag":"duplicate-table-mapping","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}