Skip to content

Commit

Permalink
HHH-17064 Fetch mode select causes StackOverflowError if used togethe…
Browse files Browse the repository at this point in the history
…r with fetch type lazy
  • Loading branch information
dreab8 committed Aug 30, 2023
1 parent fe7a8cd commit c21a430
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ private void setIsOwningInitializer(Object entityIdentifier,LoadingEntityEntry e
if ( existingLoadingEntry.getEntityInitializer() == this ) {
isOwningInitializer = true;
}
else {
isInitialized = true;
}
}
else {
isOwningInitializer = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ public void initializeInstance(RowProcessingState rowProcessingState) {
return;
}

final EntityInitializer parentEntityInitializer = parentAccess.findFirstEntityInitializer();
if ( parentEntityInitializer != null && parentEntityInitializer.isEntityInitialized() ) {
isInitialized = true;
return;
}

if ( !isAttributeAssignableToConcreteDescriptor() ) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public void setUp(SessionFactoryScope scope) {
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" );

Expand All @@ -84,8 +87,24 @@ public void tesGetAgency(SessionFactoryScope scope) {
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,ad1_0.agency_id,ad1_0.agency_detail,a1_0.agency_txt from agency_table a1_0 left join agency_detail_table ad1_0 on ad1_0.agency_id=a1_0.agency_id where a1_0.agency_id=?"
Expand All @@ -102,10 +121,6 @@ public void tesGetAgency(SessionFactoryScope scope) {
assertThat( executedQueries.get( 3 ).toLowerCase() ).isEqualTo(
"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=?"
);

assertThat( executedQueries.get( 4 ).toLowerCase() ).isEqualTo(
"select ad1_0.agency_id,ad1_0.agency_detail from agency_detail_table ad1_0 where ad1_0.agency_id=?"
);
}
);
}
Expand Down Expand Up @@ -212,6 +227,14 @@ public static class AgencyDetail {
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() {
Expand Down

0 comments on commit c21a430

Please sign in to comment.