hibernate/hibernate-orm · error · AnnotationException
Collection '<role>' is declared with a raw type and has an e
Error message
Collection '<role>' is declared with a raw type and has an explicit 'targetEntity'
What it means
Error "Collection '<role>' is declared with a raw type and has an explicit 'targetEntity'" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java:1534
modelsContext(),
usage -> {
if ( result[0] == null
&& nullIfEmpty( usage.graph() ) == null
&& usage.subgraph().length == 0 ) {
result[0] = usage;
}
}
);
return result[0];
}
TypeDetails getElementType() {
if ( isDefault( targetEntity ) ) {
if ( collectionElementType != null ) {
return collectionElementType;
}
else {
throw new AnnotationException( "Collection '" + safeCollectionRole()
+ "' is declared with a raw type and has an explicit 'targetEntity'" );
}
}
else {
return targetEntity;
}
}
SecondPass getSecondPass() {
return new CollectionSecondPass( collection ) {
@Override
public void secondPass(Map<String, PersistentClass> persistentClasses) {
bindStarToManySecondPass( persistentClasses );
}
};
}
/**View on GitHub (pinned to fad1729dce)
Solutions
- Either parameterize the collection with a generic type and drop targetEntity, or keep the raw type with explicit targetEntity, not both.
When it happens
Trigger: A collection mapping uses an annotation or annotation combination that Hibernate forbids for collections.
Common situations: Collections carrying conflicting ordering/sorting (@Sort* vs @OrderBy/@OrderColumn), misplaced @JoinColumn, or annotations only valid for single-valued associations.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/c14a4f24f677c1db.
Report an issue: GitHub.