hibernate/hibernate-orm · error · AnnotationException

Unknown entity name

Error message

Unknown entity name '{}'

What it means

Second-pass failure for @MapsId-style references: the referenced entity name is not present in persistentClasses, so the dependent identifier value cannot be linked. The target entity of the association was never mapped in this metadata build.

Solutions

  1. Correct the entity name to one that is registered in the persistence unit.
  2. If a custom entity name is used, make sure it matches the name declared in @Entity(name=...).
Defensive patterns

Strategy: validation

When it happens

Trigger: An association or reference targets a type that Hibernate has not mapped as an entity.

Common situations: Missing @Entity on the target class, the class not being scanned into the persistence unit, or a typo in the entity name.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java:1491

		@Override
		public String getReferencedEntityName() {
			return referencedEntityName;
		}

		@Override
		public boolean isInPrimaryKey() {
			// @MapsId is not itself in the primary key,
			// so it's safe to simply process it after all the primary keys have been processed.
			return true;
		}

		@Override
		public void doSecondPass(Map<String, PersistentClass> persistentClasses) {
			final var referencedEntity = persistentClasses.get( referencedEntityName );
			if ( referencedEntity == null ) {
				// TODO: much better error message if this is something that can really happen!
				throw new AnnotationException( "Unknown entity name '" + referencedEntityName + "'" );
			}
			linkJoinColumnWithValueOverridingNameIfImplicit(
					referencedEntity,
					referencedEntity.getKey(),
					joinColumns,
					value
			);
		}
	}
}

View on GitHub (pinned to fad1729dce)