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 c24d1816d7
commit bf55736a39
No known key found for this signature in database
GPG Key ID: D1D0C3030AE3AA35
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