HHH-16770 Only expand top level entity valued paths for group/order by

This commit is contained in:
Marco Belladelli 2023-06-08 10:46:08 +02:00
parent 15310330f8
commit 8408849a50
1 changed files with 2 additions and 1 deletions

View File

@ -256,7 +256,8 @@ public class EntityValuedPathInterpretation<T> extends AbstractSqmPathInterpreta
SqmToSqlAstConverter sqlAstCreationState) {
final boolean expandToAllColumns;
final Clause currentClause = sqlAstCreationState.getCurrentClauseStack().getCurrent();
if ( currentClause == Clause.GROUP || currentClause == Clause.ORDER ) {
if ( sqlAstCreationState.getCurrentProcessingState().isTopLevel() &&
( currentClause == Clause.GROUP || currentClause == Clause.ORDER ) ) {
final SqmQuerySpec<?> querySpec = (SqmQuerySpec<?>) sqlAstCreationState.getCurrentSqmQueryPart();
if ( currentClause == Clause.ORDER && !querySpec.groupByClauseContains( navigablePath ) ) {
// We must ensure that the order by expression be expanded but only if the group by