HHH-16642 Restrict conjuct type predicate to treated roots

This commit is contained in:
Marco Belladelli 2023-06-16 16:05:55 +02:00
parent 00d13050f1
commit 4095e16212

View File

@ -2990,7 +2990,7 @@ private void registerPathAttributeEntityNameUsage(SqmPath<?> sqmPath, TableGroup
entityNameUse = EntityNameUse.OPTIONAL_TREAT; entityNameUse = EntityNameUse.OPTIONAL_TREAT;
} }
else { else {
entityNameUse = EntityNameUse.TREAT; entityNameUse = EntityNameUse.BASE_TREAT;
} }
registerEntityNameUsage( registerEntityNameUsage(
tableGroup, tableGroup,
@ -5005,12 +5005,16 @@ private Expression withTreatRestriction(Expression expression, SqmPath<?> path)
} }
if ( !( expression.getExpressionType() instanceof BasicValuedMapping ) ) { if ( !( expression.getExpressionType() instanceof BasicValuedMapping ) ) {
// A case wrapper for non-basic paths is not possible, // A case wrapper for non-basic paths is not possible,
// because a case expression must return a scalar value, // because a case expression must return a scalar value.
// so we instead add the type restriction predicate as conjunct if ( lhs instanceof SqmRoot ) {
// by registering the treat into tableGroupEntityNameUses // For treated roots we need to add the type restriction predicate as conjunct
final String treatedName = treatedPath.getTreatTarget().getHibernateEntityName(); // by registering the treat into tableGroupEntityNameUses.
final TableGroup tableGroup = getFromClauseIndex().findTableGroup( wrappedPath.getNavigablePath() ); // Joins don't need the restriction as it will be embedded into
registerEntityNameUsage( tableGroup, EntityNameUse.TREAT, treatedName ); // the joined table group itself by #pruneTableGroupJoins
final String treatedName = treatedPath.getTreatTarget().getHibernateEntityName();
final TableGroup tableGroup = getFromClauseIndex().findTableGroup( wrappedPath.getNavigablePath() );
registerEntityNameUsage( tableGroup, EntityNameUse.TREAT, treatedName );
}
return expression; return expression;
} }
final BasicValuedPathInterpretation<?> basicPath = (BasicValuedPathInterpretation<?>) expression; final BasicValuedPathInterpretation<?> basicPath = (BasicValuedPathInterpretation<?>) expression;