{"record":{"id":"4ae382e6393c27f9","repo":"hibernate/hibernate-orm","slug":"duplicate-generator-name-s-you-will-likely-wan","errorCode":null,"errorMessage":"Duplicate generator name '%s'; you will likely want to set the property 'hibernate.jpa.compliance.global_id_generators' to false ","messagePattern":"Duplicate generator name '(.+?)'; you will likely want to set the property 'hibernate\\.jpa\\.compliance\\.global_id_generators' to false ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java","lineNumber":650,"sourceCode":"\tpublic java.util.Collection<Table> collectTableMappings() {\n\t\tfinal ArrayList<Table> tables = new ArrayList<>();\n\t\tfor ( Namespace namespace : getDatabase().getNamespaces() ) {\n\t\t\ttables.addAll( namespace.getTables() );\n\t\t}\n\t\treturn tables;\n\t}\n\n\t@Override\n\tpublic void addIdentifierGenerator(IdentifierGeneratorDefinition generator) {\n\t\tif ( generator == null || generator.getName() == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Id generator object or name is null\" );\n\t\t}\n\t\telse if ( !generator.getName().isEmpty()\n\t\t\t\t\t&& !defaultIdentifierGeneratorNames.contains( generator.getName() ) ) {\n\t\t\tfinal var old = idGeneratorDefinitionMap.put( generator.getName(), generator );\n\t\t\tif ( old != null && !old.equals( generator ) ) {\n\t\t\t\tif ( bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {\n\t\t\t\t\tthrow new IllegalArgumentException( \"Duplicate generator name '\" + old.getName()\n\t\t\t\t\t\t\t+ \"'; you will likely want to set the property '\"\n\t\t\t\t\t\t\t+ JpaComplianceSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE\n\t\t\t\t\t\t\t+ \"' to false \" );\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tBOOT_LOGGER.duplicateGeneratorName( old.getName() );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t}\n\n\t@Override\n\tpublic void addDefaultIdentifierGenerator(IdentifierGeneratorDefinition generator) {\n\t\taddIdentifierGenerator( generator );\n\t\tdefaultIdentifierGeneratorNames.add( generator.getName() );\n\t}\n","sourceCodeStart":632,"sourceCodeEnd":668,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java#L632-L668","documentation":"When JPA global generator scope compliance (hibernate.jpa.compliance.global_id_generators) is enabled, generator names must be unique across the persistence unit: registering a second, different IdentifierGeneratorDefinition under an existing name throws IllegalArgumentException naming the duplicate and suggesting the compliance property. An identical redefinition is allowed (the old.equals(generator) check), and when compliance is off duplicates only log a warning.","triggerScenarios":"Two entities defining @SequenceGenerator/@TableGenerator (or XML <generator>) with the same name but different attributes, while bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() is true - the default in JPA-bootstrapped environments (InFlightMetadataCollectorImpl.java:647-656).","commonSituations":"Copy-pasted @SequenceGenerator(name=\"seq\") with different sequenceName values on multiple entities; a shared 'default' generator name reused across modules; upgrading to Hibernate 6 where compliance semantics changed.","solutions":["Rename one of the conflicting generator definitions to a unique name (keeps JPA compliance)","Declare the generator once and reference it from both entities via @GeneratedValue(generator=\"name\") so there is a single definition","If redefinition is intentional, set hibernate.jpa.compliance.global_id_generators=false so duplicates only log a warning"],"exampleFix":"// before: same name, different definitions, JPA compliance on\n@SequenceGenerator(name = \"seq\", sequenceName = \"a_seq\")   // entity A\n@SequenceGenerator(name = \"seq\", sequenceName = \"b_seq\")   // entity B -> throws\n\n// after: unique names (or one shared, identical definition)\n@SequenceGenerator(name = \"user_seq\", sequenceName = \"user_seq\")\n@SequenceGenerator(name = \"order_seq\", sequenceName = \"order_seq\")","handlingStrategy":"validation","validationCode":"// Pre-check before registering a generator definition\nIdentifierGeneratorDefinition existing = metadata.getIdentifierGenerator(def.getName());\nif (existing != null && !existing.equals(def)) {\n    throw new IllegalStateException(\n            \"generator name conflict, rename one definition: \" + def.getName());\n}\n// identical redefinition or a new name is safe","typeGuard":null,"tryCatchPattern":"try {\n    metadata.buildSessionFactory();\n}\ncatch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Duplicate generator name\")) {\n        // rename one generator, or set hibernate.jpa.compliance.global_id_generators=false deliberately\n    }\n    throw e;\n}","preventionTips":["Adopt a per-entity generator naming convention (e.g. User_seq, Order_seq)","If redefining generators under one name is intended, set hibernate.jpa.compliance.global_id_generators=false as a conscious decision"],"tags":["hibernate","jpa","id-generator","duplicate","configuration"],"backgroundTag":"duplicate-generator-name","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}