hibernate/hibernate-orm · error · IllegalArgumentException
Root entity is not a subtype of '{}'
Error message
Root entity is not a subtype of '{}' What it means
Error "Root entity is not a subtype of '{}'" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/restriction/NamedAttributeRange.java:34
* Restricts an attribute of an entity to a given {@link Range},
* using a stringly-typed attribute reference.
*
* @param <X> The entity type
* @param <U> The attribute type
*
* @author Gavin King
*/
record NamedAttributeRange<X, U>(Class<X> entity, String attributeName, Range<U> range) implements Restriction<X> {
@Override
public Restriction<X> negated() {
return new Negation<>( this );
}
@Override
public Predicate toPredicate(Root<? extends X> root, CriteriaBuilder builder) {
final EntityType<? extends X> entityType = root.getModel();
if ( !entity.isAssignableFrom( entityType.getJavaType() ) ) {
throw new IllegalArgumentException( "Root entity is not a subtype of '" + entity.getTypeName() + "'" );
}
final Attribute<?, ?> attribute = entityType.getAttribute( attributeName );
if ( !(attribute instanceof SingularAttribute) ) {
throw new IllegalArgumentException( "Attribute '" + attributeName + "' is not singular" );
}
final Class<? extends U> rangeType = range.getType();
if ( rangeType != null && !rangeType.isAssignableFrom( attribute.getJavaType() ) ) {
throw new IllegalArgumentException( "Attribute '" + attributeName
+ "' is not assignable to range of type '" + rangeType.getName() + "'" );
}
return range.toPredicate( root.get( attributeName ), builder );
}
}
View on GitHub (pinned to fad1729dce)
Solutions
- The root entity is not a subtype of the required type. Apply the restriction to a query whose root extends the required type.
When it happens
Trigger: A restriction targets an entity hierarchy mismatch: Root entity is not a subtype of '<value>'
Common situations: Applying a NamedAttributeRange whose root is not a subtype of the required entity.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/ca335442d69f9e59.
Report an issue: GitHub.