HHH-18503 Register root table name usage for persisters with physical discriminators

This commit is contained in:
Marco Belladelli 2024-08-20 10:29:57 +02:00
parent ecf4c29a60
commit 67269a6137
2 changed files with 12 additions and 3 deletions

View File

@ -5810,8 +5810,7 @@ public abstract class AbstractEntityPersister
private ModelPart getIdentifierModelPart(String name, EntityMappingType treatTargetType) {
final EntityIdentifierMapping identifierMapping = getIdentifierMappingForJoin();
if ( identifierMapping instanceof NonAggregatedIdentifierMapping ) {
NonAggregatedIdentifierMapping mapping = (NonAggregatedIdentifierMapping) identifierMapping;
if ( identifierMapping instanceof final NonAggregatedIdentifierMapping mapping ) {
final ModelPart subPart = mapping.findSubPart( name, treatTargetType );
if ( subPart != null ) {
return subPart;

View File

@ -3022,10 +3022,20 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
parentType.getRootEntityDescriptor().getEntityName()
);
}
final EntityDiscriminatorMapping discriminator = parentType.getDiscriminatorMapping();
final String entityName;
if ( discriminator != null && discriminator.hasPhysicalColumn() && !parentType.getSubMappingTypes().isEmpty() ) {
// This is needed to preserve optimization for joined + discriminator inheritance
// see JoinedSubclassEntityPersister#getIdentifierMappingForJoin
entityName = parentType.getRootEntityDescriptor().getEntityName();
}
else {
entityName = parentType.getEntityName();
}
registerEntityNameUsage(
tableGroup,
EntityNameUse.EXPRESSION,
parentType.getEntityName()
entityName
);
}
else {