{"record":{"id":"535d7e6ba074201d","repo":"hibernate/hibernate-orm","slug":"duplicate-generator-name-s-you-will-likely-want","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/models/internal/GlobalRegistrationsImpl.java","lineNumber":982,"sourceCode":"\tpublic void collectSequenceGenerator(SequenceGeneratorRegistration generatorRegistration) {\n\t\tcheckGeneratorName( generatorRegistration.name() );\n\n\t\tif ( sequenceGeneratorRegistrations == null ) {\n\t\t\tsequenceGeneratorRegistrations = new HashMap<>();\n\t\t}\n\t\tsequenceGeneratorRegistrations.put( generatorRegistration.name(), generatorRegistration );\n\t}\n\n\tprivate void checkGeneratorName(String name) {\n\t\tcheckGeneratorName( name, sequenceGeneratorRegistrations );\n\t\tcheckGeneratorName( name, tableGeneratorRegistrations );\n\t\tcheckGeneratorName( name, genericGeneratorRegistrations );\n\t}\n\n\tprivate void checkGeneratorName(String name, Map<String, ?> generatorMap) {\n\t\tif ( generatorMap != null && generatorMap.containsKey( name ) ) {\n\t\t\tif ( bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Duplicate generator name \" + name + \"; you will likely want to set the property \" + AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE + \" to false \" );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tBOOT_LOGGER.duplicateGeneratorName( name );\n\t\t\t}\n\t\t}\n\t}\n\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// Table generator\n\n\tpublic void collectTableGenerators(List<JaxbTableGeneratorImpl> jaxbGenerators) {\n\t\tjaxbGenerators.forEach( jaxbGenerator -> {\n\t\t\tfinal var annotation = TABLE_GENERATOR.createUsage( sourceModelContext );\n\t\t\tif ( isNotEmpty( jaxbGenerator.getName() ) ) {\n\t\t\t\tannotation.name( jaxbGenerator.getName() );\n\t\t\t}","sourceCodeStart":964,"sourceCodeEnd":1000,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java#L964-L1000","documentation":"With JPA global-generator-scope compliance enabled (hibernate.jpa.compliance.global_id_generators, the default), generator names must be unique across the whole persistence unit: @SequenceGenerator, @TableGenerator and @GenericGenerator registrations (annotations and XML) share the checked registries. checkGeneratorName throws IllegalArgumentException on the second registration of the same name, with the message suggesting the compliance property as an escape hatch.","triggerScenarios":"Two mappings declare the same generator name - e.g. @SequenceGenerator(name='order_seq', ...) on two different entities, the same <sequence-generator name='order_seq'> appearing in two mapping.xml files, or one name reused across different generator kinds - while global generator scope compliance is on.","commonSituations":"Generator names shared across modules assembled into one persistence unit; a generator declared both as an annotation and again in orm.xml 'for override'; teams unaware that the name space is global by default under JPA compliance.","solutions":["Rename one generator so every name is unique within the persistence unit, and update the generator= references that point at it","Delete the redundant declaration - e.g. the orm.xml copy that merely restates the annotated generator","If duplication is intentional for modules reused across different units, set hibernate.jpa.compliance.global_id_generators=false and accept the lenient Hibernate behavior (duplicates then only log a warning)"],"exampleFix":"// before - two entities in the same persistence unit\n@SequenceGenerator(name = \"order_seq\", sequenceName = \"order_seq\")\npublic class Order { }\n@SequenceGenerator(name = \"order_seq\", sequenceName = \"cust_order_seq\")\npublic class CustomerOrder { }\n\n// after - unique names\n@SequenceGenerator(name = \"order_seq\", sequenceName = \"order_seq\")\npublic class Order { }\n@SequenceGenerator(name = \"cust_order_seq\", sequenceName = \"cust_order_seq\")\npublic class CustomerOrder { }","handlingStrategy":"validation","validationCode":"// Pre-flight: assert generator-name uniqueness across the persistence unit (JPA global scope)\nMap<String, String> seen = new java.util.HashMap<>();\nfor (Class<?> c : entityClasses) {\n    for (var a : c.getAnnotations()) {\n        if (a instanceof jakarta.persistence.SequenceGenerator g)\n            record(seen, g.name(), c);\n        if (a instanceof jakarta.persistence.TableGenerator g)\n            record(seen, g.name(), c);\n    }\n}\n// record(...) stores name->class and throws IllegalStateException on a duplicate","typeGuard":null,"tryCatchPattern":"try { sessionFactory = metadata.buildSessionFactory(); } catch (IllegalArgumentException e) { /* message names the duplicate generator and suggests hibernate.jpa.compliance.global_id_generators - rename the duplicate (preferred) or disable global scope compliance deliberately */ throw new IllegalStateException(\"Duplicate generator name: \" + e.getMessage(), e); }","preventionTips":["Adopt a naming convention that makes generator names globally unique (entity-prefixed)","Declare shared generators once (e.g. in orm.xml or a package-info) and reference them by name","Only set hibernate.jpa.compliance.global_id_generators=false when the duplication is intentional and understood"],"tags":["hibernate","jpa","id-generation","sequence-generator","configuration","orm"],"backgroundTag":"duplicate-generator-name","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}