{"record":{"id":"4d3189235372237e","repo":"hibernate/hibernate-orm","slug":"collate-is-not-allowed-for-position-based-order","errorCode":null,"errorMessage":"'collate' is not allowed for position based 'order by' or 'group by' items","messagePattern":"'collate' is not allowed for position based 'order by' or 'group by' items","errorType":"exception","errorClass":"SyntaxException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":1622,"sourceCode":"\t\tfinal List<SqmExpression<?>> expressions = new ArrayList<>( size );\n\t\tfor ( int i = 0; i < size; i++ ) {\n\t\t\texpressions.add( (SqmExpression<?>) groupByExpressionContexts.get( i ).accept( this ) );\n\t\t}\n\t\treturn expressions;\n\t}\n\n\tprivate SqmExpression<?> resolveOrderByOrGroupByExpression(\n\t\t\tParseTree child,\n\t\t\tboolean definedCollate,\n\t\t\tboolean allowPositionalOrAliases) {\n\t\tfinal var nodeBuilder = nodeBuilder();\n\t\tfinal var processingState = processingStateStack.getCurrent();\n\t\tfinal var processingQuery = processingState.getProcessingQuery();\n\t\tfinal var queryPart = sqmQueryPart( processingQuery );\n\t\tif ( child instanceof TerminalNode ) {\n\t\t\tif ( definedCollate ) {\n\t\t\t\t// This is syntactically disallowed\n\t\t\t\tthrow new SyntaxException( \"'collate' is not allowed for position based 'order by' or 'group by' items\" );\n\t\t\t}\n\t\t\telse if ( !allowPositionalOrAliases ) {\n\t\t\t\t// This is syntactically disallowed\n\t\t\t\tthrow new SyntaxException( \"Position based 'order by' is not allowed in 'over' or 'within group' clauses\" );\n\t\t\t}\n\n\t\t\tfinal int position = Integer.parseInt( child.getText() );\n\n\t\t\t// make sure this selection exists\n\t\t\tfinal var nodeByPosition = nodeByPosition( queryPart, position, processingState );\n\t\t\tif ( nodeByPosition == null ) {\n\t\t\t\tthrow new SemanticException( \"Numeric literal '\" + position\n\t\t\t\t\t\t+ \"' used in 'group by' does not match a registered select item\",\n\t\t\t\t\t\tquery );\n\t\t\t}\n\n\t\t\treturn new SqmAliasedNodeRef(\n\t\t\t\t\tposition,","sourceCodeStart":1604,"sourceCodeEnd":1640,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L1604-L1640","documentation":"Error \"'collate' is not allowed for position based 'order by' or 'group by' items\" thrown in hibernate/hibernate-orm.","triggerScenarios":"The HQL/JPQL query violates a structural language rule.","commonSituations":"Writing queries with missing select/from, mismatched group by positions, or invalid ordering constructs.","solutions":["Remove 'collate' from position-based order/group-by items.","Use alias- or path-based items when collation is needed."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}