HHH-11903 : @OneToOne Derived ID is null when returned by query when bidirectional

This commit is contained in:
Gail Badner 2018-10-23 19:26:42 -07:00
parent 1cd56964c6
commit 4741fa4f33
2 changed files with 10 additions and 6 deletions

View File

@ -13,6 +13,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import org.hibernate.AnnotationException;
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
import org.hibernate.annotations.LazyGroup;
import org.hibernate.annotations.common.reflection.XClass;
@ -235,10 +236,15 @@ public class OneToOneSecondPass implements SecondPass {
boolean referenceToPrimaryKey = referencesDerivedId || mappedBy == null;
value.setReferenceToPrimaryKey( referenceToPrimaryKey );
// If the other side is a derived ID, prevent an infinite
// loop of attempts to resolve identifiers.
if ( referencesDerivedId ) {
( (ManyToOne) otherSideProperty.getValue() ).setReferenceToPrimaryKey( false );
// If the other side is a derived ID, and both sides are eager using FetchMode.JOIN,
// prevent an infinite loop of attempts to resolve identifiers by making
// this side use FetchMode.SELECT.
if ( referencesDerivedId &&
!value.isLazy() &&
value.getFetchMode() == FetchMode.JOIN &&
!otherSideProperty.isLazy() &&
otherSideProperty.getValue().getFetchMode() == FetchMode.JOIN ) {
value.setFetchMode( FetchMode.SELECT );
}
String propertyRef = value.getReferencedPropertyName();

View File

@ -25,9 +25,7 @@ import org.junit.Test;
public class OneToOneWithDerivedIdentityTest extends BaseCoreFunctionalTestCase {
@Test
//@TestForIssue(jiraKey = "HHH-5695")
@TestForIssue(jiraKey = "HHH-11903")
@FailureExpected(jiraKey = "HHH-11903")
public void testInsertFooAndBarWithDerivedId() {
Session s = openSession();
s.beginTransaction();