{"record":{"id":"7fd0071c436df18c","repo":"hibernate/hibernate-orm","slug":"strict-jpa-query-language-compliance-was-violated-7fd007","errorCode":null,"errorMessage":"Strict JPA query language compliance was violated: use of ORDER BY clause in subquery","messagePattern":"Strict JPA query language compliance was violated: use of ORDER BY clause in subquery","errorType":"exception","errorClass":"StrictJpaComplianceViolation","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":1154,"sourceCode":"\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif ( processingStateStack.depth() > 1 && sqmQueryPart.getOrderByClause() == null ) {\n\t\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\t\t\"A 'limit', 'offset', or 'fetch' clause requires an 'order by' clause when used in a subquery\",\n\t\t\t\t\t\t\tquery\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tsetOffsetFetchLimit( sqmQueryPart, limitClauseContext, offsetClauseContext, fetchClauseContext );\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected void visitOrderBy(SqmQueryPart<?> sqmQueryPart, HqlParser.OrderByClauseContext ctx) {\n\t\tif ( ctx != null ) {\n\t\t\tif ( creationOptions.useStrictJpaCompliance() && processingStateStack.depth() > 1 ) {\n\t\t\t\tthrow new StrictJpaComplianceViolation(\n\t\t\t\t\t\tStrictJpaComplianceViolation.Type.SUBQUERY_ORDER_BY\n\t\t\t\t);\n\t\t\t}\n\t\t\tsqmQueryPart.setOrderByClause( visitOrderByClause( ctx ) );\n\t\t}\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\tprivate void setOffsetFetchLimit(SqmQueryPart<?> sqmQueryPart, HqlParser.LimitClauseContext limitClauseContext, HqlParser.OffsetClauseContext offsetClauseContext, HqlParser.FetchClauseContext fetchClauseContext) {\n\t\t// these casts are all fine because the parser only accepts literals and parameters\n\t\tsqmQueryPart.setOffsetExpression( (SqmExpression<? extends Number>) visitOffsetClause(offsetClauseContext) );\n\t\tif ( limitClauseContext == null ) {\n\t\t\tsqmQueryPart.setFetchExpression(\n\t\t\t\t\t(SqmExpression<? extends Number>) visitFetchClause(fetchClauseContext),\n\t\t\t\t\tvisitFetchClauseType(fetchClauseContext)\n\t\t\t);\n\t\t}\n\t\telse if ( fetchClauseContext == null ) {","sourceCodeStart":1136,"sourceCodeEnd":1172,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L1136-L1172","documentation":"Error \"Strict JPA query language compliance was violated: use of ORDER BY clause in subquery\" thrown in hibernate/hibernate-orm.","triggerScenarios":"An HQL extension is used while strict JPQL compliance is enabled.","commonSituations":"Running HQL-specific syntax (CTEs, limit/offset, collection functions) with hibernate.jpa.compliance.query=true.","solutions":["Disable strict JPA compliance to allow ORDER BY in subqueries.","Remove the ORDER BY from the subquery."],"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"}