HHH-17413 Avoid pruning table references used in type() expression

This commit is contained in:
Marco Belladelli 2023-12-04 13:33:29 +01:00 committed by Christian Beikov
parent 3d61b9658c
commit 6159713119
1 changed files with 13 additions and 7 deletions

View File

@ -3151,6 +3151,11 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
// The AND junction allows to create an intersection of entity name lists of all sub-predicates
final EntityMappingType mappingType = (EntityMappingType) tableGroup.getModelPart().getPartMappingType();
final AbstractEntityPersister persister = (AbstractEntityPersister) mappingType.getEntityPersister();
if ( getCurrentClauseStack().getCurrent() != Clause.WHERE && getCurrentClauseStack().getCurrent() != Clause.HAVING ) {
// Where and having clauses are handled specially with EntityNameUse.FILTER and pruning
registerEntityNameUsage( tableGroup, EntityNameUse.PROJECTION, persister.getEntityName(), true );
}
else {
// Avoid doing this for single table entity persisters, as the table span includes secondary tables,
// which we don't want to resolve, though we know that there is only a single table anyway
if ( persister instanceof SingleTableEntityPersister ) {
@ -3161,6 +3166,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
tableGroup.resolveTableReference( null, persister.getSubclassTableName( i ) );
}
}
}
protected void pruneTableGroupJoins() {
for ( Map.Entry<TableGroup, Map<String, EntityNameUse>> entry : tableGroupEntityNameUses.entrySet() ) {