hibernate/hibernate-orm · error · IllegalStateException

The JPA specification does not support the fetch or offset c

Error message

The JPA specification does not support the fetch or offset clause. Please disable the JPA query compliance if you want to use this feature.

What it means

Error "The JPA specification does not support the fetch or offset clause. Please disable the JPA query compliance if you want to use this feature." thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmSelectStatement.java:558

		return this;
	}

	@Nonnull
	@Override
	public JpaCriteriaQuery<T> fetch(@Nullable Number fetch, FetchClauseType fetchClauseType) {
		validateComplianceFetchOffset();
		getQueryPart().setFetch( nodeBuilder().value( fetch ), fetchClauseType );
		return this;
	}

	@Override
	public FetchClauseType getFetchClauseType() {
		return getQueryPart().getFetchClauseType();
	}

	private void validateComplianceFetchOffset() {
		if ( nodeBuilder().isJpaQueryComplianceEnabled() ) {
			throw new IllegalStateException(
					"The JPA specification does not support the fetch or offset clause. " +
							"Please disable the JPA query compliance if you want to use this feature." );
		}
	}

	@Override
	@Nonnull
	public SqmSelectStatement<Long> createCountQuery() {
		final SqmSelectStatement<Long> copy = createCopy( noParamCopyContext(), Long.class );
		final SqmQueryPart<Long> queryPart = copy.getQueryPart();
		//TODO: detect queries with no 'group by', but aggregate functions
		//      in 'select' list (we don't even need to hit the database to
		//      know they return exactly one row)
		if ( queryPart instanceof SqmQuerySpec<?> querySpec
				&& !querySpec.isDistinct()
				&& querySpec.getGroupingExpressions().isEmpty() ) {
			// we can just remove any fetch joins and
			// replace the select list with count(*)

View on GitHub (pinned to fad1729dce)

Solutions

  1. Disable JPA query compliance to allow the fetch/offset clause.
  2. Use JPA-standard pagination instead: Query#setFirstResult and Query#setMaxResults.
  3. Use HQL or native SQL where the fetch/offset clause is supported.

When it happens

Trigger: A fetch or offset clause is set on a query while JPA query compliance mode is enabled; plain JPA does not support them.

Common situations: Using setFirstResult/setMaxResults equivalents or LIMIT/OFFSET extensions; disable JPA compliance or use standard pagination.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/8934c9659e9d972e. Report an issue: GitHub.