hibernate/hibernate-orm · error · StrictJpaComplianceViolation
Strict JPA query language compliance was violated: use of OR
Error message
Strict JPA query language compliance was violated: use of ORDER BY clause in subquery
What it means
Error "Strict JPA query language compliance was violated: use of ORDER BY clause in subquery" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:1154
);
}
if ( processingStateStack.depth() > 1 && sqmQueryPart.getOrderByClause() == null ) {
throw new SemanticException(
"A 'limit', 'offset', or 'fetch' clause requires an 'order by' clause when used in a subquery",
query
);
}
setOffsetFetchLimit( sqmQueryPart, limitClauseContext, offsetClauseContext, fetchClauseContext );
}
}
}
protected void visitOrderBy(SqmQueryPart<?> sqmQueryPart, HqlParser.OrderByClauseContext ctx) {
if ( ctx != null ) {
if ( creationOptions.useStrictJpaCompliance() && processingStateStack.depth() > 1 ) {
throw new StrictJpaComplianceViolation(
StrictJpaComplianceViolation.Type.SUBQUERY_ORDER_BY
);
}
sqmQueryPart.setOrderByClause( visitOrderByClause( ctx ) );
}
}
@SuppressWarnings("unchecked")
private void setOffsetFetchLimit(SqmQueryPart<?> sqmQueryPart, HqlParser.LimitClauseContext limitClauseContext, HqlParser.OffsetClauseContext offsetClauseContext, HqlParser.FetchClauseContext fetchClauseContext) {
// these casts are all fine because the parser only accepts literals and parameters
sqmQueryPart.setOffsetExpression( (SqmExpression<? extends Number>) visitOffsetClause(offsetClauseContext) );
if ( limitClauseContext == null ) {
sqmQueryPart.setFetchExpression(
(SqmExpression<? extends Number>) visitFetchClause(fetchClauseContext),
visitFetchClauseType(fetchClauseContext)
);
}
else if ( fetchClauseContext == null ) {View on GitHub (pinned to fad1729dce)
Solutions
- Disable strict JPA compliance to allow ORDER BY in subqueries.
- Remove the ORDER BY from the subquery.
When it happens
Trigger: An HQL extension is used while strict JPQL compliance is enabled.
Common situations: Running HQL-specific syntax (CTEs, limit/offset, collection functions) with hibernate.jpa.compliance.query=true.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/7fd0071c436df18c.
Report an issue: GitHub.