HHH-17328 Add discriminator to entity graph with inheritance subtypes

This commit is contained in:
Marco Belladelli 2023-11-15 14:14:10 +01:00
parent aec7887a66
commit da070f8f5a
1 changed files with 9 additions and 3 deletions

View File

@ -8183,16 +8183,22 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
final TableGroup actualTableGroup = joinedTableGroup instanceof PluralTableGroup ?
( (PluralTableGroup) joinedTableGroup ).getElementTableGroup() :
joinedTableGroup;
final MappingType entityMappingType = actualTableGroup == null
final MappingType mappingType = actualTableGroup == null
? null
: actualTableGroup.getModelPart().getPartMappingType();
if ( entityMappingType instanceof EntityMappingType ) {
if ( mappingType instanceof EntityMappingType ) {
final EntityMappingType entityMappingType = (EntityMappingType) mappingType;
registerEntityNameUsage(
actualTableGroup,
EntityNameUse.PROJECTION,
( (EntityMappingType) entityMappingType ).getEntityName(),
entityMappingType.getEntityName(),
true
);
if ( entityMappingType.getSuperMappingType() != null ) {
// A joined table group was created by an enabled entity graph or fetch profile,
// and it's of an inheritance subtype, so we should apply the discriminator
entityMappingType.applyDiscriminator( null, null, actualTableGroup, this );
}
}
}
if ( fetchable instanceof PluralAttributeMapping ) {