hibernate/hibernate-orm · error · AnnotationException
Association '<qualify(entityClassName, path)>' targets the t
Error message
Association '<qualify(entityClassName, path)>' targets the type '<targetEntityName>' [which does not belong to the same persistence unit|which is not an '@Entity' type]
What it means
Error "Association '<qualify(entityClassName, path)>' targets the type '<targetEntityName>' [which does not belong to the same persistence unit|which is not an '@Entity' type]" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/ToOneFkSecondPass.java:113
}
}
}
}
return false;
}
@Override
public void doSecondPass(java.util.Map<String, PersistentClass> persistentClasses) throws MappingException {
if ( value instanceof ManyToOne manyToOne ) {
//TODO: move this validation logic to a separate ManyToOneSecondPass
// for consistency with how this is handled for OneToOnes
final String targetEntityName = manyToOne.getReferencedEntityName();
final var targetEntity = persistentClasses.get( targetEntityName );
if ( targetEntity == null ) {
final String problem = annotatedEntity
? " which does not belong to the same persistence unit"
: " which is not an '@Entity' type";
throw new AnnotationException( "Association '" + qualify( entityClassName, path )
+ "' targets the type '" + targetEntityName + "'" + problem );
}
manyToOne.setPropertyName( path );
final String propertyRef = columns.getReferencedProperty();
if ( propertyRef != null ) {
handlePropertyRef(
targetEntity,
manyToOne,
path,
propertyRef,
buildingContext
);
}
else {
createSyntheticPropertyReference(
columns,
targetEntity,
persistentClass,View on GitHub (pinned to fad1729dce)
Solutions
- Annotate the target class with @Entity (or add it to orm.xml) and make sure it is included in the same persistence unit / scanned packages.
- If the target is intentionally external, replace the association with a basic id attribute instead of an entity reference.
Example fix
Annotate the target class with @Entity (or add it to orm.xml) and make sure it is included in the same persistence unit / scanned packages.
When it happens
Trigger: An entity mapping annotation or bootstrap configuration violates a Hibernate mapping rule.
Common situations: Annotation mapping mistakes: inverse-side @Id associations, @Column on @OneToOne, unmapped association targets, mismatched @EnumeratedValue/@Temporal usage, duplicate sequence generators.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/983528923010a754.
Report an issue: GitHub.