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 42df67a974..dfd05264d0 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 @@ -100,6 +100,8 @@ import org.hibernate.type.EmbeddedComponentType; import org.hibernate.type.EntityType; import org.hibernate.type.Type; +import static java.util.Objects.requireNonNullElse; + /** * @author Steve Ebersole */ @@ -1373,16 +1375,7 @@ public class ToOneAttributeMapping } } - final SqlAstJoinType joinType; - if ( requestedJoinType != null ) { - joinType = requestedJoinType; - } - else { - joinType = SqlAstJoinType.INNER; -// joinType = hasNotFoundAction() -// ? SqlAstJoinType.LEFT -// : SqlAstJoinType.INNER; - } + final SqlAstJoinType joinType = requireNonNullElse( requestedJoinType, SqlAstJoinType.INNER ); // If a parent is a collection part, there is no custom predicate and the join is INNER or LEFT // we check if this attribute is the map key property to reuse the existing index table group @@ -1431,7 +1424,7 @@ public class ToOneAttributeMapping sb.insert( 0, path.getUnaliasedLocalName() ); path = path.getParent(); } - return path != null && navigablePath.equals( path ) + return navigablePath.equals( path ) && targetKeyPropertyNames.contains( sb.toString() ) && identifyingColumnsTableExpression.equals( tableExpression ); } @@ -1552,7 +1545,7 @@ public class ToOneAttributeMapping sb.insert( 0, path.getUnaliasedLocalName() ); path = path.getParent(); } - return path != null && navigablePath.equals( path ) + return navigablePath.equals( path ) && targetKeyPropertyNames.contains( sb.toString() ) && identifyingColumnsTableExpression.equals( tableExpression ); }, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/notfound/OneToOneNotFoundTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/notfound/OneToOneNotFoundTest.java index 85f4d14c8b..77caf1900b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/notfound/OneToOneNotFoundTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/notfound/OneToOneNotFoundTest.java @@ -98,9 +98,11 @@ public class OneToOneNotFoundTest { @Test public void testOneToOne(SessionFactoryScope scope) throws Exception { scope.inTransaction( session -> { - final Show show2 = session.find( Show.class, 1 ); - assertNotNull( show2 ); - assertNull( show2.getDescription() ); + final Show show1 = session.find( Show.class, 1 ); + // we should find the show, it does exist + assertThat( show1 ).isNotNull(); + // however, IGNORE should trigger for its description + assertThat( show1.getDescription() ).isNull(); } ); }