hibernate/hibernate-orm · error · IllegalArgumentException

Duplicate generator name '%s'; you will likely want to set t

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

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.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java:650

	public java.util.Collection<Table> collectTableMappings() {
		final ArrayList<Table> tables = new ArrayList<>();
		for ( Namespace namespace : getDatabase().getNamespaces() ) {
			tables.addAll( namespace.getTables() );
		}
		return tables;
	}

	@Override
	public void addIdentifierGenerator(IdentifierGeneratorDefinition generator) {
		if ( generator == null || generator.getName() == null ) {
			throw new IllegalArgumentException( "Id generator object or name is null" );
		}
		else if ( !generator.getName().isEmpty()
					&& !defaultIdentifierGeneratorNames.contains( generator.getName() ) ) {
			final var old = idGeneratorDefinitionMap.put( generator.getName(), generator );
			if ( old != null && !old.equals( generator ) ) {
				if ( bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {
					throw new IllegalArgumentException( "Duplicate generator name '" + old.getName()
							+ "'; you will likely want to set the property '"
							+ JpaComplianceSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE
							+ "' to false " );
				}
				else {
					BOOT_LOGGER.duplicateGeneratorName( old.getName() );
				}
			}
		}

	}

	@Override
	public void addDefaultIdentifierGenerator(IdentifierGeneratorDefinition generator) {
		addIdentifierGenerator( generator );
		defaultIdentifierGeneratorNames.add( generator.getName() );
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Rename one of the conflicting generator definitions to a unique name (keeps JPA compliance)
  2. Declare the generator once and reference it from both entities via @GeneratedValue(generator="name") so there is a single definition
  3. If redefinition is intentional, set hibernate.jpa.compliance.global_id_generators=false so duplicates only log a warning

Example fix

// before: same name, different definitions, JPA compliance on
@SequenceGenerator(name = "seq", sequenceName = "a_seq")   // entity A
@SequenceGenerator(name = "seq", sequenceName = "b_seq")   // entity B -> throws

// after: unique names (or one shared, identical definition)
@SequenceGenerator(name = "user_seq", sequenceName = "user_seq")
@SequenceGenerator(name = "order_seq", sequenceName = "order_seq")
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check before registering a generator definition
IdentifierGeneratorDefinition existing = metadata.getIdentifierGenerator(def.getName());
if (existing != null && !existing.equals(def)) {
    throw new IllegalStateException(
            "generator name conflict, rename one definition: " + def.getName());
}
// identical redefinition or a new name is safe

Try / catch

try {
    metadata.buildSessionFactory();
}
catch (IllegalArgumentException e) {
    if (e.getMessage() != null && e.getMessage().contains("Duplicate generator name")) {
        // rename one generator, or set hibernate.jpa.compliance.global_id_generators=false deliberately
    }
    throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/4ae382e6393c27f9. Report an issue: GitHub.