Skip to content

Commit a4cbe2f

Browse files
committed
HHH-17096 Always initialize table group for subtype treated joins
1 parent c6c9671 commit a4cbe2f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,8 +3084,11 @@ private void registerEntityNameUsage(
30843084
(s, existingUse) -> finalEntityNameUse.stronger( existingUse )
30853085
);
30863086

3087-
// Resolve the table reference for all types which we register an entity name use for
3088-
if ( actualTableGroup.isInitialized() ) {
3087+
// Resolve the table reference for all types which we register an entity name use for.
3088+
// Also, force table group initialization for treats when needed to ensure correct cardinality
3089+
final EntityNameUse.UseKind useKind = finalEntityNameUse.getKind();
3090+
if ( actualTableGroup.isInitialized() || ( useKind == EntityNameUse.UseKind.TREAT && actualTableGroup.canUseInnerJoins()
3091+
&& !( (EntityMappingType) actualTableGroup.getModelPart().getPartMappingType() ).isTypeOrSuperType( persister ) ) ) {
30893092
actualTableGroup.resolveTableReference( null, persister.getTableName() );
30903093
}
30913094

@@ -3102,7 +3105,6 @@ private void registerEntityNameUsage(
31023105

31033106
// If we encounter a treat or projection use, we also want register the use for all subtypes.
31043107
// We do this here to not have to expand entity name uses during pruning later on
3105-
final EntityNameUse.UseKind useKind = finalEntityNameUse.getKind();
31063108
if ( useKind == EntityNameUse.UseKind.TREAT ) {
31073109
for ( EntityMappingType subType : persister.getSubMappingTypes() ) {
31083110
entityNameUses.compute(

0 commit comments

Comments
 (0)