HHH-17679 Fix unnecessary table reference resolution for treat

This commit is contained in:
Marco Belladelli 2024-01-26 15:32:43 +01:00 committed by Christian Beikov
parent 28d8ec578f
commit 7a227d702d
2 changed files with 7 additions and 7 deletions

View File

@ -1417,7 +1417,10 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
applied = applyDiscriminatorPredicate( join, join.getJoinedTableReference(), entityNameUses, metamodel );
}
assert applied : "Could not apply treat discriminator predicate to root table join";
assert i == 0 || retainedTableReferences.contains( tableReferenceJoins.get( i - 1 ).getJoinedTableReference() );
if ( i != 0 ) {
// Always retain the root table reference join where the discriminator was applied
retainedTableReferences.add( tableReferenceJoins.get( i - 1 ).getJoinedTableReference() );
}
}
}
if ( tableReferenceJoins.isEmpty() ) {

View File

@ -3089,7 +3089,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
actualTableGroup.resolveTableReference( null, persister.getTableName() );
}
final EntityNameUse.UseKind useKind = finalEntityNameUse.getKind();
if ( projection ) {
EntityMappingType superMappingType = persister;
while ( ( superMappingType = superMappingType.getSuperMappingType() ) != null ) {
@ -3100,8 +3099,10 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
);
}
}
// If we encounter a treat or projection use, we also want register the use for all subtypes.
// We do this here to not have to expand entity name uses during pruning later on
final EntityNameUse.UseKind useKind = finalEntityNameUse.getKind();
if ( useKind == EntityNameUse.UseKind.TREAT ) {
for ( EntityMappingType subType : persister.getSubMappingTypes() ) {
entityNameUses.compute(
@ -3109,10 +3110,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
(s, existingUse) -> finalEntityNameUse.stronger( existingUse )
);
}
if ( persister.isInherited() && persister.needsDiscriminator() ) {
// Make sure the table group includes the root table when needed for TREAT
actualTableGroup.resolveTableReference( persister.getRootTableName() );
}
}
else if ( useKind == EntityNameUse.UseKind.PROJECTION ) {
for ( EntityMappingType subType : persister.getSubMappingTypes() ) {
@ -3358,7 +3355,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
// This is a non-treated join with an entity which is an inheritance subtype,
// register a TREAT entity name use to filter only the entities of the correct type.
registerEntityNameUsage(
getActualTableGroup( joinedTableGroup, sqmJoin ),
elementTableGroup,
EntityNameUse.TREAT,
entityDomainType.getHibernateEntityName()
);