diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java index 4e10983beb..c210a6696d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java @@ -136,7 +136,7 @@ public class ToOneAttributeMapping hence this flag is also controlling the default join type. */ private final boolean isKeyTableNullable; - private final boolean isConstrained; + private final boolean isInternalLoadNullable; private final NotFoundAction notFoundAction; private final boolean unwrapProxy; private final boolean isOptional; @@ -294,6 +294,7 @@ public class ToOneAttributeMapping } } isOptional = ( (ManyToOne) bootValue ).isIgnoreNotFound(); + isInternalLoadNullable = ( isNullable && bootValue.isForeignKeyEnabled() ) || notFoundAction == NotFoundAction.IGNORE; } else { assert bootValue instanceof OneToOne; @@ -361,8 +362,8 @@ public class ToOneAttributeMapping notFoundAction = null; isKeyTableNullable = isNullable(); isOptional = ! bootValue.isConstrained(); + isInternalLoadNullable = isNullable(); } - isConstrained = bootValue.isConstrained(); this.navigableRole = navigableRole; this.declaringTableGroupProducer = resolveDeclaringTableGroupProducer( declaringEntityPersister ); @@ -529,7 +530,7 @@ public class ToOneAttributeMapping this.cardinality = original.cardinality; this.bidirectionalAttributeName = original.bidirectionalAttributeName; this.declaringTableGroupProducer = declaringTableGroupProducer; - this.isConstrained = original.isConstrained; + this.isInternalLoadNullable = original.isInternalLoadNullable; } private static boolean equal(Value lhsValue, Value rhsValue) { @@ -1049,8 +1050,8 @@ public class ToOneAttributeMapping && parentNavigablePath.equals( fetchParent.getNavigablePath().getRealParent() ); - if ( hasNotFoundAction() - || ( fetchTiming == FetchTiming.IMMEDIATE && selected ) ) { + if ( (hasNotFoundAction() + || ( fetchTiming == FetchTiming.IMMEDIATE && selected )) ) { final TableGroup tableGroup = determineTableGroup( fetchablePath, fetchParent, @@ -1655,8 +1656,8 @@ public class ToOneAttributeMapping return isOptional; } - public boolean isConstrained(){ - return isConstrained; + public boolean isInternalLoadNullable() { + return isInternalLoadNullable; } public NotFoundAction getNotFoundAction() { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/BatchEntitySelectFetchInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/BatchEntitySelectFetchInitializer.java index 55b0522fd9..889cbd4a34 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/BatchEntitySelectFetchInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/BatchEntitySelectFetchInitializer.java @@ -221,7 +221,7 @@ public class BatchEntitySelectFetchInitializer extends AbstractFetchParentAccess entityKey.getEntityName(), entityKey.getIdentifier(), true, - referencedModelPart.isNullable() + referencedModelPart.isInternalLoadNullable() ); if ( instance != null ) { ( (AbstractEntityPersister) referencedModelPart.getDeclaringType() ).setPropertyValue( diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntitySelectFetchInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntitySelectFetchInitializer.java index 62aab9cd2f..c25e4341cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntitySelectFetchInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntitySelectFetchInitializer.java @@ -48,7 +48,6 @@ public class EntitySelectFetchInitializer extends AbstractFetchParentAccess impl protected final DomainResultAssembler keyAssembler; private final ToOneAttributeMapping toOneMapping; - private Object entityIdentifier; protected boolean isInitialized; protected Object entityInstance; @@ -199,7 +198,7 @@ public class EntitySelectFetchInitializer extends AbstractFetchParentAccess impl entityName, entityIdentifier, true, - toOneMapping.isNullable() || toOneMapping.isIgnoreNotFound() + toOneMapping.isInternalLoadNullable() ); if ( entityInstance == null ) { @@ -241,7 +240,6 @@ public class EntitySelectFetchInitializer extends AbstractFetchParentAccess impl @Override public void finishUpRow(RowProcessingState rowProcessingState) { - entityIdentifier = null; entityInstance = null; isInitialized = false; clearResolutionListeners(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/notfound/EagerProxyNotFoundTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/notfound/EagerProxyNotFoundTest.java index f9d64d06d5..c5c87403de 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/notfound/EagerProxyNotFoundTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/notfound/EagerProxyNotFoundTest.java @@ -19,10 +19,8 @@ import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; import org.hibernate.proxy.HibernateProxy; -import org.hibernate.testing.TestForIssue; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.JiraKey; -import org.hibernate.testing.orm.junit.NotImplementedYet; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.junit.jupiter.api.AfterEach; @@ -133,7 +131,6 @@ public class EagerProxyNotFoundTest { } @Test - @NotImplementedYet( strict = false ) public void testExistingProxyWithNonExistingAssociation(SessionFactoryScope scope) { scope.inTransaction( session -> { @@ -166,7 +163,6 @@ public class EagerProxyNotFoundTest { } @Test - @NotImplementedYet( strict = false ) public void testEnityWithNotExistingAssociation(SessionFactoryScope scope) { scope.inTransaction( session -> {