{"record":{"id":"ca335442d69f9e59","repo":"hibernate/hibernate-orm","slug":"root-entity-is-not-a-subtype-of","errorCode":null,"errorMessage":"Root entity is not a subtype of '{}'","messagePattern":"Root entity is not a subtype of '(.+?)'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/restriction/NamedAttributeRange.java","lineNumber":34,"sourceCode":" * Restricts an attribute of an entity to a given {@link Range},\n * using a stringly-typed attribute reference.\n *\n * @param <X> The entity type\n * @param <U> The attribute type\n *\n * @author Gavin King\n */\nrecord NamedAttributeRange<X, U>(Class<X> entity, String attributeName, Range<U> range) implements Restriction<X> {\n\t@Override\n\tpublic Restriction<X> negated() {\n\t\treturn new Negation<>( this );\n\t}\n\n\t@Override\n\tpublic Predicate toPredicate(Root<? extends X> root, CriteriaBuilder builder) {\n\t\tfinal EntityType<? extends X> entityType = root.getModel();\n\t\tif ( !entity.isAssignableFrom( entityType.getJavaType() ) ) {\n\t\t\tthrow new IllegalArgumentException( \"Root entity is not a subtype of '\" + entity.getTypeName() + \"'\" );\n\t\t}\n\t\tfinal Attribute<?, ?> attribute = entityType.getAttribute( attributeName );\n\t\tif ( !(attribute instanceof SingularAttribute) ) {\n\t\t\tthrow new IllegalArgumentException( \"Attribute '\" + attributeName + \"' is not singular\" );\n\t\t}\n\t\tfinal Class<? extends U> rangeType = range.getType();\n\t\tif ( rangeType != null && !rangeType.isAssignableFrom( attribute.getJavaType() ) ) {\n\t\t\tthrow new IllegalArgumentException( \"Attribute '\" + attributeName\n\t\t\t\t\t\t\t\t\t\t\t\t+ \"' is not assignable to range of type '\" + rangeType.getName() + \"'\" );\n\t\t}\n\t\treturn range.toPredicate( root.get( attributeName ), builder );\n\t}\n}\n","sourceCodeStart":16,"sourceCodeEnd":48,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/restriction/NamedAttributeRange.java#L16-L48","documentation":"Error \"Root entity is not a subtype of '{}'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A restriction targets an entity hierarchy mismatch: Root entity is not a subtype of '<value>'","commonSituations":"Applying a NamedAttributeRange whose root is not a subtype of the required entity.","solutions":["The root entity is not a subtype of the required type. Apply the restriction to a query whose root extends the required type."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}