From 2105234f5f5bc39366b36d5d87131209174aa277 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Thu, 24 Aug 2023 10:55:44 +0200 Subject: [PATCH] HHH-17085 Improved check for entity-valued group by path expansion --- .../EntityValuedPathInterpretation.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java index 8f839e64b4..66b8d5d921 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java @@ -33,7 +33,6 @@ import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.select.SqmDynamicInstantiation; import org.hibernate.query.sqm.tree.select.SqmDynamicInstantiationArgument; import org.hibernate.query.sqm.tree.select.SqmQuerySpec; -import org.hibernate.query.sqm.tree.select.SqmSelectableNode; import org.hibernate.query.sqm.tree.select.SqmSelection; import org.hibernate.spi.NavigablePath; import org.hibernate.sql.ast.Clause; @@ -50,6 +49,8 @@ import org.hibernate.sql.ast.tree.update.Assignable; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetchable; +import jakarta.persistence.criteria.Selection; + public class EntityValuedPathInterpretation extends AbstractSqmPathInterpretation implements SqlTupleContainer, Assignable { private final Expression sqlExpression; @@ -361,20 +362,27 @@ public class EntityValuedPathInterpretation extends AbstractSqmPathInterpreta ? Collections.emptyList() : sqmQuerySpec.getSelectClause().getSelections(); for ( SqmSelection selection : selections ) { - if ( selectableNodeContains( selection.getSelectableNode(), path ) ) { + if ( selectionContains( selection.getSelectableNode(), path ) ) { return true; } } return false; } - private static boolean selectableNodeContains(SqmSelectableNode selectableNode, NavigablePath path) { - if ( selectableNode instanceof SqmPath && path.isParentOrEqual( ( (SqmPath) selectableNode ).getNavigablePath() ) ) { + private static boolean selectionContains(Selection selection, NavigablePath path) { + if ( selection instanceof SqmPath && path.isParentOrEqual( ( (SqmPath) selection ).getNavigablePath() ) ) { return true; } - else if ( selectableNode instanceof SqmDynamicInstantiation ) { - for ( SqmDynamicInstantiationArgument argument : ( (SqmDynamicInstantiation) selectableNode ).getArguments() ) { - if ( selectableNodeContains( argument.getSelectableNode(), path ) ) { + else if ( selection.isCompoundSelection() ) { + for ( Selection compoundSelection : selection.getCompoundSelectionItems() ) { + if ( selectionContains( compoundSelection, path ) ) { + return true; + } + } + } + else if ( selection instanceof SqmDynamicInstantiation ) { + for ( SqmDynamicInstantiationArgument argument : ( (SqmDynamicInstantiation) selection ).getArguments() ) { + if ( selectionContains( argument.getSelectableNode(), path ) ) { return true; } }