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 ? final TableGroup actualTableGroup = joinedTableGroup instanceof PluralTableGroup ?
( (PluralTableGroup) joinedTableGroup ).getElementTableGroup() : ( (PluralTableGroup) joinedTableGroup ).getElementTableGroup() :
joinedTableGroup; joinedTableGroup;
final MappingType entityMappingType = actualTableGroup == null final MappingType mappingType = actualTableGroup == null
? null ? null
: actualTableGroup.getModelPart().getPartMappingType(); : actualTableGroup.getModelPart().getPartMappingType();
if ( entityMappingType instanceof EntityMappingType ) { if ( mappingType instanceof EntityMappingType ) {
final EntityMappingType entityMappingType = (EntityMappingType) mappingType;
registerEntityNameUsage( registerEntityNameUsage(
actualTableGroup, actualTableGroup,
EntityNameUse.PROJECTION, EntityNameUse.PROJECTION,
( (EntityMappingType) entityMappingType ).getEntityName(), entityMappingType.getEntityName(),
true 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 ) { if ( fetchable instanceof PluralAttributeMapping ) {