@@ -3089,7 +3089,6 @@ private void registerEntityNameUsage(
3089
3089
actualTableGroup .resolveTableReference ( null , persister .getTableName () );
3090
3090
}
3091
3091
3092
- final EntityNameUse .UseKind useKind = finalEntityNameUse .getKind ();
3093
3092
if ( projection ) {
3094
3093
EntityMappingType superMappingType = persister ;
3095
3094
while ( ( superMappingType = superMappingType .getSuperMappingType () ) != null ) {
@@ -3100,19 +3099,17 @@ private void registerEntityNameUsage(
3100
3099
);
3101
3100
}
3102
3101
}
3102
+
3103
3103
// If we encounter a treat or projection use, we also want register the use for all subtypes.
3104
3104
// We do this here to not have to expand entity name uses during pruning later on
3105
+ final EntityNameUse .UseKind useKind = finalEntityNameUse .getKind ();
3105
3106
if ( useKind == EntityNameUse .UseKind .TREAT ) {
3106
3107
for ( EntityMappingType subType : persister .getSubMappingTypes () ) {
3107
3108
entityNameUses .compute (
3108
3109
subType .getEntityName (),
3109
3110
(s , existingUse ) -> finalEntityNameUse .stronger ( existingUse )
3110
3111
);
3111
3112
}
3112
- if ( persister .isInherited () && persister .needsDiscriminator () ) {
3113
- // Make sure the table group includes the root table when needed for TREAT
3114
- actualTableGroup .resolveTableReference ( persister .getRootTableName () );
3115
- }
3116
3113
}
3117
3114
else if ( useKind == EntityNameUse .UseKind .PROJECTION ) {
3118
3115
for ( EntityMappingType subType : persister .getSubMappingTypes () ) {
@@ -3358,7 +3355,7 @@ private TableGroup consumeAttributeJoin(
3358
3355
// This is a non-treated join with an entity which is an inheritance subtype,
3359
3356
// register a TREAT entity name use to filter only the entities of the correct type.
3360
3357
registerEntityNameUsage (
3361
- getActualTableGroup ( joinedTableGroup , sqmJoin ) ,
3358
+ elementTableGroup ,
3362
3359
EntityNameUse .TREAT ,
3363
3360
entityDomainType .getHibernateEntityName ()
3364
3361
);
0 commit comments