HHH-18272 Check for `SqmAliasedNodeRef` when collecting group/order by
This commit is contained in:
parent
5e4c35441c
commit
c972208fbc
|
@ -80,6 +80,7 @@ import org.hibernate.type.internal.BasicTypeImpl;
|
||||||
import org.hibernate.type.internal.ConvertedBasicTypeImpl;
|
import org.hibernate.type.internal.ConvertedBasicTypeImpl;
|
||||||
import org.hibernate.type.spi.TypeConfiguration;
|
import org.hibernate.type.spi.TypeConfiguration;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.hibernate.internal.util.NullnessUtil.castNonNull;
|
import static org.hibernate.internal.util.NullnessUtil.castNonNull;
|
||||||
import static org.hibernate.query.sqm.tree.jpa.ParameterCollector.collectParameters;
|
import static org.hibernate.query.sqm.tree.jpa.ParameterCollector.collectParameters;
|
||||||
|
|
||||||
|
@ -214,12 +215,7 @@ public class SqmUtil {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<NavigablePath> navigablePaths = new ArrayList<>( expressions.size() );
|
return collectNavigablePaths( expressions );
|
||||||
final SqmPathVisitor pathVisitor = new SqmPathVisitor( path -> navigablePaths.add( path.getNavigablePath() ) );
|
|
||||||
for ( SqmExpression<?> expression : expressions ) {
|
|
||||||
expression.accept( pathVisitor );
|
|
||||||
}
|
|
||||||
return navigablePaths;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<NavigablePath> getOrderByNavigablePaths(SqmQuerySpec<?> querySpec) {
|
public static List<NavigablePath> getOrderByNavigablePaths(SqmQuerySpec<?> querySpec) {
|
||||||
|
@ -228,11 +224,26 @@ public class SqmUtil {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<SqmSortSpecification> sortSpecifications = order.getSortSpecifications();
|
final List<SqmExpression<?>> expressions = order.getSortSpecifications()
|
||||||
final List<NavigablePath> navigablePaths = new ArrayList<>( sortSpecifications.size() );
|
.stream()
|
||||||
|
.map( SqmSortSpecification::getSortExpression )
|
||||||
|
.collect( toList() );
|
||||||
|
return collectNavigablePaths( expressions );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<NavigablePath> collectNavigablePaths(final List<SqmExpression<?>> expressions) {
|
||||||
|
final List<NavigablePath> navigablePaths = new ArrayList<>( expressions.size() );
|
||||||
final SqmPathVisitor pathVisitor = new SqmPathVisitor( path -> navigablePaths.add( path.getNavigablePath() ) );
|
final SqmPathVisitor pathVisitor = new SqmPathVisitor( path -> navigablePaths.add( path.getNavigablePath() ) );
|
||||||
for ( SqmSortSpecification sortSpec : sortSpecifications ) {
|
for ( final SqmExpression<?> expression : expressions ) {
|
||||||
sortSpec.getSortExpression().accept( pathVisitor );
|
if ( expression instanceof SqmAliasedNodeRef ) {
|
||||||
|
final NavigablePath navigablePath = ( (SqmAliasedNodeRef) expression ).getNavigablePath();
|
||||||
|
if ( navigablePath != null ) {
|
||||||
|
navigablePaths.add( navigablePath );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
expression.accept( pathVisitor );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return navigablePaths;
|
return navigablePaths;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue