HHH-17064 Fetch mode select causes StackOverflowError if used together with fetch type lazy

This commit is contained in:
Andrea Boriero 2023-08-16 16:53:41 +02:00 committed by Andrea Boriero
parent d3c8331ddf
commit 04ecfaaa73
3 changed files with 37 additions and 4 deletions

View File

@ -614,6 +614,9 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
if ( existingLoadingEntry.getEntityInitializer() == this ) {
isOwningInitializer = true;
}
else {
isInitialized = true;
}
}
else {
isOwningInitializer = true;

View File

@ -109,6 +109,12 @@ public class EntitySelectFetchInitializer extends AbstractFetchParentAccess impl
return;
}
final EntityInitializer parentEntityInitializer = parentAccess.findFirstEntityInitializer();
if ( parentEntityInitializer != null && parentEntityInitializer.isEntityInitialized() ) {
isInitialized = true;
return;
}
if ( !isAttributeAssignableToConcreteDescriptor() ) {
return;
}

View File

@ -61,6 +61,9 @@ public class DepthOneTest {
session -> {
Agency agency = new Agency( 1, "Test Agency" );
AgencyDetail agencyDetail = new AgencyDetail( 1, "abc" );
agency.setAgencyDetail( agencyDetail );
session.persist( agencyDetail );
session.persist( agency );
Group group = new Group( 1, "Test Group 1" );
@ -84,8 +87,24 @@ public class DepthOneTest {
session -> {
Agency agency = session.get( Agency.class, 1 );
assertThat( agency ).isNotNull();
assertThat( agency.getAgencyDetail() ).isNotNull();
Set<Group> groups = agency.getGroups();
assertThat( groups.size() ).isEqualTo( 1 );
Group group = groups.iterator().next();
assertThat( group.getAgency() ).isNotNull();
assertThat( group.getAgency() ).isSameAs( agency );
Set<User> users = group.getUsers();
assertThat( users.size() ).isEqualTo( 8 );
for ( User user : users ) {
assertThat( user.getAgency() ).isNotNull();
assertThat( user.getAgency() ).isSameAs( agency );
}
List<String> executedQueries = statementInspector.getSqlQueries();
assertThat( executedQueries.size() ).isEqualTo( 5 );
assertThat( executedQueries.size() ).isEqualTo( 4 );
assertThat( executedQueries.get( 0 ).toLowerCase() ).isEqualTo(
"select a1_0.agency_id,a2_0.agency_id,a2_0.agency_detail,a1_0.agency_txt from agency_table a1_0 left join agency_detail_table a2_0 on a2_0.agency_id=a1_0.agency_id where a1_0.agency_id=?"
@ -103,9 +122,6 @@ public class DepthOneTest {
"select u1_0.group_id,u1_1.user_id,a1_0.agency_id,a1_0.agency_txt,u1_1.user_name from group_user u1_0 join user_table u1_1 on u1_1.user_id=u1_0.user_id left join agency_table a1_0 on a1_0.agency_id=u1_1.agency_id where u1_0.group_id in(select g1_0.group_id from group_table g1_0 where g1_0.agency_id=?)"
);
assertThat( executedQueries.get( 4 ).toLowerCase() ).isEqualTo(
"select a1_0.agency_id,a1_0.agency_detail from agency_detail_table a1_0 where a1_0.agency_id=?"
);
}
);
}
@ -212,6 +228,14 @@ public class DepthOneTest {
private Integer agencyId = null;
private String agencyDetail = null;
public AgencyDetail() {
}
public AgencyDetail(Integer agencyId, String agencyDetail) {
this.agencyId = agencyId;
this.agencyDetail = agencyDetail;
}
@Id
@Column(name = "AGENCY_ID")
public Integer getAgencyId() {