diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java index 694079b14c7e..9073bde7839e 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java @@ -508,6 +508,18 @@ private void handleNaturalId(Property property) { + "' belongs to an entity subclass and may not be annotated '@NaturalId'" + " (only a property of a root '@Entity' or a '@MappedSuperclass' may be a '@NaturalId')" ); } + if ( memberDetails.hasDirectAnnotationUsage( ManyToOne.class ) ) { + if ( memberDetails.getDirectAnnotationUsage( ManyToOne.class ).fetch() == LAZY ) { + throw new AnnotationException( "Property '" + qualify( holder.getPath(), name ) + + " is annotated '@NaturalId' and '@ManyToOne(fetch=LAZY)' (natural id fields may not be lazy)" ); + } + } + if ( memberDetails.hasDirectAnnotationUsage( Basic.class ) ) { + if ( memberDetails.getDirectAnnotationUsage( Basic.class ).fetch() == LAZY ) { + throw new AnnotationException( "Property '" + qualify( holder.getPath(), name ) + + " is annotated '@NaturalId' and '@Basic(fetch=LAZY)' (natural id fields may not be lazy)" ); + } + } if ( !naturalId.mutable() ) { updatable = false; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java index 8132e017cd37..7766213de3cc 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java @@ -2022,11 +2022,7 @@ private Property createManyToOneAttribute( Property prop = new Property(); prop.setValue( manyToOneBinding ); - bindProperty( - sourceDocument, - manyToOneSource, - prop - ); + bindProperty( sourceDocument, manyToOneSource, prop ); if ( isNotEmpty( manyToOneSource.getCascadeStyleName() ) ) { // todo : would be better to delay this the end of binding (second pass, etc)