hibernate/hibernate-orm · error · SyntaxException
'collate' is not allowed for position based 'order by' or 'g
Error message
'collate' is not allowed for position based 'order by' or 'group by' items
What it means
Error "'collate' is not allowed for position based 'order by' or 'group by' items" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:1622
final List<SqmExpression<?>> expressions = new ArrayList<>( size );
for ( int i = 0; i < size; i++ ) {
expressions.add( (SqmExpression<?>) groupByExpressionContexts.get( i ).accept( this ) );
}
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,View on GitHub (pinned to fad1729dce)
Solutions
- Remove 'collate' from position-based order/group-by items.
- Use alias- or path-based items when collation is needed.
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/4d3189235372237e.
Report an issue: GitHub.