HHH-14390 : StackOverflowError with @Fetch(FetchMode.SELECT) mapped for entity with an ID that is a bidirectional one-to-one eager association

This commit is contained in:
Gail Badner 2021-02-10 15:41:54 -08:00 committed by gbadner
parent 611796c0fc
commit 8a01b4dab4
2 changed files with 6 additions and 8 deletions

View File

@ -237,14 +237,15 @@ public class OneToOneSecondPass implements SecondPass {
boolean referenceToPrimaryKey = referencesDerivedId || mappedBy == null;
value.setReferenceToPrimaryKey( referenceToPrimaryKey );
// 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 the other side is an entity with an ID that is derived from
// this side's owner entity, and both sides of the association are eager,
// then this side must be set to FetchMode.SELECT; otherwise,
// there will be an infinite loop attempting to load the derived ID on
// the opposite side.
if ( referencesDerivedId &&
!value.isLazy() &&
value.getFetchMode() == FetchMode.JOIN &&
!otherSideProperty.isLazy() &&
otherSideProperty.getValue().getFetchMode() == FetchMode.JOIN ) {
!otherSideProperty.isLazy() ) {
value.setFetchMode( FetchMode.SELECT );
}

View File

@ -36,7 +36,6 @@ public class OneToOneEagerDerivedIdFetchModeSelectTest extends BaseCoreFunctiona
@Test
@TestForIssue(jiraKey = "HHH-14390")
@FailureExpected(jiraKey = "HHH-14390")
public void testQuery() {
doInHibernate( this::sessionFactory, session -> {
@ -52,7 +51,6 @@ public class OneToOneEagerDerivedIdFetchModeSelectTest extends BaseCoreFunctiona
@Test
@TestForIssue(jiraKey = "HHH-14390")
@FailureExpected(jiraKey = "HHH-14390")
public void testQueryById() {
doInHibernate( this::sessionFactory, session -> {
@ -82,7 +80,6 @@ public class OneToOneEagerDerivedIdFetchModeSelectTest extends BaseCoreFunctiona
@Test
@TestForIssue(jiraKey = "HHH-14390")
@FailureExpected(jiraKey = "HHH-14390")
public void testFindByPrimaryKey() {
doInHibernate( this::sessionFactory, session -> {