File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
hibernate-core/src/main/java/org/hibernate/query/sqm/sql Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff 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 (
You can’t perform that action at this time.
0 commit comments