hibernate/hibernate-orm · error · AnnotationException
Association '<role>' targets the type '<typeName>' which is
Error message
Association '<role>' targets the type '<typeName>' which is not an '@Entity' type
What it means
Error "Association '<role>' targets the type '<typeName>' which is not an '@Entity' type" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java:2579
Class<T> annotationClass, MemberDetails property, MetadataBuildingContext context) {
final var fromProperty = property.getDirectAnnotationUsage( annotationClass );
if ( fromProperty != null ) {
return fromProperty;
}
// Check the owning entity class hierarchy (class-level annotation propagates to collections)
final var modelsContext = context.getBootstrapContext().getModelsContext();
final var fromClass = property.getDeclaringType().getAnnotationUsage( annotationClass, modelsContext );
return fromClass == null ?
extractFromPackage( annotationClass, property.getDeclaringType(), context ) :
fromClass;
}
private void handleUnownedManyToMany(
TypeDetails elementType,
PersistentClass collectionEntity,
boolean isCollectionOfEntities) {
if ( !isCollectionOfEntities ) {
throw new AnnotationException( "Association '" + safeCollectionRole() + "'"
+ targetEntityMessage( elementType ) );
}
joinColumns.setManyToManyOwnerSideEntityName( collectionEntity.getEntityName() );
final var mappedByPropertyValue =
getMappedByProperty( elementType, collectionEntity )
.getValue();
final var table =
mappedByPropertyValue instanceof Collection collectionProperty
// this is a collection on the other side
? collectionProperty.getCollectionTable()
// this is a ToOne with a @JoinTable or a regular property
: mappedByPropertyValue.getTable();
collection.setCollectionTable( table );
processSoftDeletes();
processTemporal();
processAudited();View on GitHub (pinned to fad1729dce)
Solutions
- Annotate the target type with @Entity, or change the association to target an entity type.
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/bc9941f6a9335b4c.
Report an issue: GitHub.