HHH-15099 - Improve handling of associations marked with @NotFound

- clean-up
This commit is contained in:
Steve Ebersole 2022-03-04 13:13:40 -06:00
parent c5ac528a24
commit ed5831f482
2 changed files with 10 additions and 15 deletions

View File

@ -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 );
},

View File

@ -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();
} );
}