Skip to content

Commit e8b5a23

Browse files
mbelladebeikov
authored andcommitted
HHH-17629 Reuse compatible joins for entity graphs and fetch profiles
1 parent 3b0ec32 commit e8b5a23

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8148,21 +8148,33 @@ else if ( getLoadQueryInfluencers().hasEnabledFetchProfiles() ) {
81488148
fetchablePath,
81498149
np -> {
81508150
// generate the join
8151+
final TableGroup tableGroup;
81518152
final TableGroup lhs = fromClauseIndex.getTableGroup( fetchParent.getNavigablePath() );
8152-
final TableGroupJoin tableGroupJoin = ( (TableGroupJoinProducer) fetchable ).createTableGroupJoin(
8153-
fetchablePath,
8154-
lhs,
8155-
alias,
8156-
null,
8157-
null,
8158-
true,
8159-
false,
8160-
BaseSqmToSqlAstConverter.this
8153+
final TableGroupJoinProducer joinProducer = (TableGroupJoinProducer) fetchable;
8154+
final TableGroup compatibleTableGroup = lhs.findCompatibleJoinedGroup(
8155+
joinProducer,
8156+
joinProducer.determineSqlJoinType( lhs, null, true )
81618157
);
8162-
lhs.addTableGroupJoin( tableGroupJoin );
8158+
if ( compatibleTableGroup == null ) {
8159+
final TableGroupJoin tableGroupJoin = joinProducer.createTableGroupJoin(
8160+
fetchablePath,
8161+
lhs,
8162+
alias,
8163+
null,
8164+
null,
8165+
true,
8166+
false,
8167+
BaseSqmToSqlAstConverter.this
8168+
);
8169+
lhs.addTableGroupJoin( tableGroupJoin );
8170+
tableGroup = tableGroupJoin.getJoinedGroup();
8171+
}
8172+
else {
8173+
tableGroup = compatibleTableGroup;
8174+
}
81638175

81648176
// and return the joined group
8165-
return tableGroupJoin.getJoinedGroup();
8177+
return tableGroup;
81668178
}
81678179
);
81688180
}

0 commit comments

Comments
 (0)