hibernate/hibernate-orm · error · IllegalArgumentException
Duplicate generator name %s; you will likely want to set the
Error message
Duplicate generator name %s; you will likely want to set the property hibernate.jpa.compliance.global_id_generators to false
What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java:982
public void collectSequenceGenerator(SequenceGeneratorRegistration generatorRegistration) {
checkGeneratorName( generatorRegistration.name() );
if ( sequenceGeneratorRegistrations == null ) {
sequenceGeneratorRegistrations = new HashMap<>();
}
sequenceGeneratorRegistrations.put( generatorRegistration.name(), generatorRegistration );
}
private void checkGeneratorName(String name) {
checkGeneratorName( name, sequenceGeneratorRegistrations );
checkGeneratorName( name, tableGeneratorRegistrations );
checkGeneratorName( name, genericGeneratorRegistrations );
}
private void checkGeneratorName(String name, Map<String, ?> generatorMap) {
if ( generatorMap != null && generatorMap.containsKey( name ) ) {
if ( bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {
throw new IllegalArgumentException(
"Duplicate generator name " + name + "; you will likely want to set the property " + AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE + " to false " );
}
else {
BOOT_LOGGER.duplicateGeneratorName( name );
}
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Table generator
public void collectTableGenerators(List<JaxbTableGeneratorImpl> jaxbGenerators) {
jaxbGenerators.forEach( jaxbGenerator -> {
final var annotation = TABLE_GENERATOR.createUsage( sourceModelContext );
if ( isNotEmpty( jaxbGenerator.getName() ) ) {
annotation.name( jaxbGenerator.getName() );
}View on GitHub (pinned to fad1729dce)
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)
Example fix
// before - two entities in the same persistence unit
@SequenceGenerator(name = "order_seq", sequenceName = "order_seq")
public class Order { }
@SequenceGenerator(name = "order_seq", sequenceName = "cust_order_seq")
public class CustomerOrder { }
// after - unique names
@SequenceGenerator(name = "order_seq", sequenceName = "order_seq")
public class Order { }
@SequenceGenerator(name = "cust_order_seq", sequenceName = "cust_order_seq")
public class CustomerOrder { } Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight: assert generator-name uniqueness across the persistence unit (JPA global scope)
Map<String, String> seen = new java.util.HashMap<>();
for (Class<?> c : entityClasses) {
for (var a : c.getAnnotations()) {
if (a instanceof jakarta.persistence.SequenceGenerator g)
record(seen, g.name(), c);
if (a instanceof jakarta.persistence.TableGenerator g)
record(seen, g.name(), c);
}
}
// record(...) stores name->class and throws IllegalStateException on a duplicate Try / catch
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); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Duplicate generator name '%s'; you will likely want to set t
- Duplicate named query '%s'
- Duplicate named stored procedure '{}'
- Duplicate SQL result set mapping '{}'
- Duplicate table mapping '{}'
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/535d7e6ba074201d.
Report an issue: GitHub.