HHH-17085 Improved check for entity-valued group by path expansion

This commit is contained in:
Marco Belladelli 2023-08-24 10:55:44 +02:00
parent b47b021b97
commit 90a6bf760a
1 changed files with 15 additions and 7 deletions

View File

@ -30,7 +30,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;
@ -47,6 +46,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<T> extends AbstractSqmPathInterpretation<T>
implements SqlTupleContainer, Assignable {
@ -352,20 +353,27 @@ public class EntityValuedPathInterpretation<T> 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;
}
}