Skip to content

Commit

Permalink
HHH-11903 : @OnetoOne Derived ID is null when returned by query when …
Browse files Browse the repository at this point in the history
…bidirectional

(cherry picked from commit 4741fa4)
  • Loading branch information
gbadner committed Feb 11, 2021
1 parent 7ccbe09 commit a2fff33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Expand Up @@ -13,6 +13,7 @@
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;
Expand Down Expand Up @@ -236,10 +237,15 @@ else if ( otherSideProperty.getValue() instanceof ManyToOne ) {
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();
Expand Down
Expand Up @@ -25,9 +25,7 @@

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();
Expand Down

0 comments on commit a2fff33

Please sign in to comment.