Skip to content

Commit

Permalink
HHH-16642 Restrict conjuct type predicate to treated roots
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed Jun 28, 2023
1 parent bc445f6 commit 256a93f
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2990,7 +2990,7 @@ private void registerPathAttributeEntityNameUsage(SqmPath<?> sqmPath, TableGroup
entityNameUse = EntityNameUse.OPTIONAL_TREAT;
}
else {
entityNameUse = EntityNameUse.TREAT;
entityNameUse = EntityNameUse.BASE_TREAT;
}
registerEntityNameUsage(
tableGroup,
Expand Down Expand Up @@ -4993,12 +4993,16 @@ private Expression withTreatRestriction(Expression expression, SqmPath<?> path)
}
if ( !( expression.getExpressionType() instanceof BasicValuedMapping ) ) {
// A case wrapper for non-basic paths is not possible,
// because a case expression must return a scalar value,
// so we instead add the type restriction predicate as conjunct
// by registering the treat into tableGroupEntityNameUses
final String treatedName = treatedPath.getTreatTarget().getHibernateEntityName();
final TableGroup tableGroup = getFromClauseIndex().findTableGroup( wrappedPath.getNavigablePath() );
registerEntityNameUsage( tableGroup, EntityNameUse.TREAT, treatedName );
// because a case expression must return a scalar value.
if ( lhs instanceof SqmRoot ) {
// For treated roots we need to add the type restriction predicate as conjunct
// by registering the treat into tableGroupEntityNameUses.
// Joins don't need the restriction as it will be embedded into
// 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;
}
final BasicValuedPathInterpretation<?> basicPath = (BasicValuedPathInterpretation<?>) expression;
Expand Down

0 comments on commit 256a93f

Please sign in to comment.