hibernate/hibernate-orm · error · AnnotationException

Use of the same entity name twice: ${name}

Error message

Use of the same entity name twice: ${name}

What it means

Error "Use of the same entity name twice: ${name}" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java:1489

			throw new MappingException( "@Mutability is not allowed on entity" );
		}
	}

	private boolean isMutable() {
		return !annotatedClass.hasAnnotationUsage( Immutable.class, modelsContext() );
	}

	private void registerImportName() {
		try {
			final var metadataCollector = getMetadataCollector();
			metadataCollector.addImport( name, persistentClass.getEntityName() );
			final String entityName = persistentClass.getEntityName();
			if ( !entityName.equals( name ) ) {
				metadataCollector.addImport( entityName, entityName );
			}
		}
		catch (MappingException me) {
			throw new AnnotationException( "Use of the same entity name twice: " + name, me );
		}
	}

	private void bindRootEntity() {
		final var rootClass = (RootClass) persistentClass;
		rootClass.setMutable( isMutable() );
		if ( isNotBlank( where ) ) {
			rootClass.setWhere( where );
		}
		if ( cacheConcurrentStrategy != null ) {
			rootClass.setCacheConcurrencyStrategy( cacheConcurrentStrategy );
			rootClass.setCacheRegionName( cacheRegion );
			rootClass.setLazyPropertiesCacheable( cacheLazyProperty );
		}
		rootClass.setNaturalIdCacheRegionName( naturalIdCacheRegion );
		rootClass.setNaturalIdClass( naturalIdClass );
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Rename one of the entities so each entity name is unique in the persistence unit.

When it happens

Trigger: Two managed types are registered under the same entity name.

Common situations: Duplicate @Entity(name=...) values or two classes with the same simple name in one persistence unit.


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