{"record":{"id":"cfd9382d802f0d75","repo":"hibernate/hibernate-orm","slug":"entity-class-classname-specifies-an-sqlrest","errorCode":null,"errorMessage":"Entity class '${className}' specifies an '@SQLRestriction' but it is a subclass in an entity inheritance hierarchy (only a root class may be specify a restriction)","messagePattern":"Entity class '(.+?)' specifies an '@SQLRestriction' but it is a subclass in an entity inheritance hierarchy \\(only a root class may be specify a restriction\\)","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java","lineNumber":1463,"sourceCode":"\t\telse {\n\t\t\tcheckSubclassEntity();\n\t\t}\n\n\t\tensureNoMutabilityPlan();\n\n\t\tregisterImportName();\n\n\t\tprocessNamedEntityGraphs();\n\t}\n\n\tprivate void checkSubclassEntity() {\n\t\tif ( !isMutable() ) {\n\t\t\tthrow new AnnotationException( \"Entity class '\" + annotatedClass.getName()\n\t\t\t\t\t+ \"' is annotated '@Immutable' but it is a subclass in an entity inheritance hierarchy\"\n\t\t\t\t\t+ \" (only a root class may declare its mutability)\" );\n\t\t}\n\t\tif ( isNotBlank( where ) ) {\n\t\t\tthrow new AnnotationException( \"Entity class '\" + annotatedClass.getName()\n\t\t\t\t\t+ \"' specifies an '@SQLRestriction' but it is a subclass in an entity inheritance hierarchy\"\n\t\t\t\t\t+ \" (only a root class may be specify a restriction)\" );\n\t\t}\n\t}\n\n\tprivate void ensureNoMutabilityPlan() {\n\t\tif ( annotatedClass.hasAnnotationUsage( Mutability.class, modelsContext() ) ) {\n\t\t\tthrow new MappingException( \"@Mutability is not allowed on entity\" );\n\t\t}\n\t}\n\n\tprivate boolean isMutable() {\n\t\treturn !annotatedClass.hasAnnotationUsage( Immutable.class, modelsContext() );\n\t}\n\n\tprivate void registerImportName() {\n\t\ttry {\n\t\t\tfinal var metadataCollector = getMetadataCollector();","sourceCodeStart":1445,"sourceCodeEnd":1481,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java#L1445-L1481","documentation":"Error \"Entity class '${className}' specifies an '@SQLRestriction' but it is a subclass in an entity inheritance hierarchy (only a root class may be specify a restriction)\" thrown in hibernate/hibernate-orm.","triggerScenarios":"An annotation restricted to the root of an inheritance hierarchy is placed on a subclass (or the hierarchy rules are otherwise violated).","commonSituations":"SINGLE_TABLE/JOINED hierarchies where @Table, @DiscriminatorColumn, @DiscriminatorFormula, @Cache, @Immutable, @Id or @Version are declared on the wrong class of the hierarchy.","solutions":["Move @SQLRestriction to the root class of the entity inheritance hierarchy."],"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"}