hibernate/hibernate-orm · error · SyntaxException
Position based 'order by' is not allowed in 'over' or 'withi
Error message
Position based 'order by' is not allowed in 'over' or 'within group' clauses
What it means
Error "Position based 'order by' is not allowed in 'over' or 'within group' clauses" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:1626
return expressions;
}
private SqmExpression<?> resolveOrderByOrGroupByExpression(
ParseTree child,
boolean definedCollate,
boolean allowPositionalOrAliases) {
final var nodeBuilder = nodeBuilder();
final var processingState = processingStateStack.getCurrent();
final var processingQuery = processingState.getProcessingQuery();
final var queryPart = sqmQueryPart( processingQuery );
if ( child instanceof TerminalNode ) {
if ( definedCollate ) {
// This is syntactically disallowed
throw new SyntaxException( "'collate' is not allowed for position based 'order by' or 'group by' items" );
}
else if ( !allowPositionalOrAliases ) {
// This is syntactically disallowed
throw new SyntaxException( "Position based 'order by' is not allowed in 'over' or 'within group' clauses" );
}
final int position = Integer.parseInt( child.getText() );
// make sure this selection exists
final var nodeByPosition = nodeByPosition( queryPart, position, processingState );
if ( nodeByPosition == null ) {
throw new SemanticException( "Numeric literal '" + position
+ "' used in 'group by' does not match a registered select item",
query );
}
return new SqmAliasedNodeRef(
position,
nodeBuilder.resolveExpressible( integerDomainType ),
nodeBuilder
);
}View on GitHub (pinned to fad1729dce)
Solutions
- Use expression-based ordering inside 'over'/'within group' clauses.
- Remove the positional reference.
When it happens
Trigger: The HQL/JPQL query violates a structural language rule.
Common situations: Writing queries with missing select/from, mismatched group by positions, or invalid ordering constructs.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/5e0d84519f184a38.
Report an issue: GitHub.