hibernate/hibernate-orm · error · StrictJpaComplianceViolation

Strict JPA query language compliance was violated: use of LI

Error message

Strict JPA query language compliance was violated: use of LIMIT/OFFSET clause

What it means

Error "Strict JPA query language compliance was violated: use of LIMIT/OFFSET clause" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:1134

	public SetOperator visitSetOperator(HqlParser.SetOperatorContext ctx) {
		final var token = ( (TerminalNode) ctx.getChild( 0 ) ).getSymbol();
		final boolean all = ctx.getChildCount() == 2;
		return switch ( token.getType() ) {
			case UNION -> all ? SetOperator.UNION_ALL : SetOperator.UNION;
			case INTERSECT -> all ? SetOperator.INTERSECT_ALL : SetOperator.INTERSECT;
			case EXCEPT -> all ? SetOperator.EXCEPT_ALL : SetOperator.EXCEPT;
			default -> throw new ParsingException( "Unrecognized set operator: " + token.getText() );
		};
	}

	protected void visitLimitOffset(SqmQueryPart<?> sqmQueryPart, HqlParser.LimitOffsetContext ctx) {
		if ( ctx != null ) {
			final var limitClauseContext = ctx.limitClause();
			final var offsetClauseContext = ctx.offsetClause();
			final var fetchClauseContext = ctx.fetchClause();
			if ( limitClauseContext != null || offsetClauseContext != null || fetchClauseContext != null ) {
				if ( getCreationOptions().useStrictJpaCompliance() ) {
					throw new StrictJpaComplianceViolation(
							StrictJpaComplianceViolation.Type.LIMIT_OFFSET_CLAUSE
					);
				}

				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 ) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Disable strict JPA compliance to use limit/offset in HQL.
  2. Use setMaxResults/setFirstResult instead of LIMIT/OFFSET syntax.

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/21b4be859394e80b. Report an issue: GitHub.