diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java index 54ad0312b9..fce04fc42a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java @@ -1310,10 +1310,8 @@ public class EntityBinder { if ( persistentClass instanceof RootClass ) { bindRootEntity(); } - else if ( !isMutable() ) { - throw new AnnotationException("Entity class '" + annotatedClass.getName() - + "' is annotated '@Immutable' but it is a subclass in an entity inheritance hierarchy" - + " (only root classes may declare mutability)"); + else { + checkSubclassEntity(); } ensureNoMutabilityPlan(); @@ -1323,6 +1321,19 @@ public class EntityBinder { processNamedEntityGraphs(); } + private void checkSubclassEntity() { + if ( !isMutable() ) { + throw new AnnotationException( "Entity class '" + annotatedClass.getName() + + "' is annotated '@Immutable' but it is a subclass in an entity inheritance hierarchy" + + " (only a root class may declare its mutability)" ); + } + if ( isNotEmpty( where ) ) { + throw new AnnotationException( "Entity class '" + annotatedClass.getName() + + "' specifies an '@SQLRestriction' but it is a subclass in an entity inheritance hierarchy" + + " (only a root class may be specify a restriction)" ); + } + } + private void ensureNoMutabilityPlan() { if ( annotatedClass.hasAnnotationUsage( Mutability.class, getSourceModelContext() ) ) { throw new MappingException( "@Mutability is not allowed on entity" );