hibernate/hibernate-orm · error · IllegalArgumentException

Fetch-size is not relevant for non-select NativeQuery

Error message

Fetch-size is not relevant for non-select NativeQuery

What it means

Error "Fetch-size is not relevant for non-select NativeQuery" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java:905

	@Override
	@Nullable
	public PessimisticLockScope getLockScope() {
		//noinspection removal
		return queryOptions.getLockOptions().getLockScope();
	}

	@Override
	protected void applyReadOnlyHint(String hintName, Object value) {
		if ( isNotSelectForSure() ) {
			throw new IllegalArgumentException( "Read-only is not relevant for non-select NativeQuery" );
		}
		super.applyReadOnlyHint( hintName, value );
	}

	@Override
	protected void applyFetchSizeHint(String hintName, Object value) {
		if ( isNotSelectForSure() ) {
			throw new IllegalArgumentException( "Fetch-size is not relevant for non-select NativeQuery" );
		}
		super.applyFetchSizeHint( hintName, value );
	}

	@Override
	protected void applyResultCachingHint(String hintName, Object value) {
		if ( isNotSelectForSure() ) {
			throw new IllegalArgumentException( "Result-caching is not relevant for non-select NativeQuery" );
		}
		super.applyResultCachingHint( hintName, value );
	}

	@Override
	protected void applyResultCacheModeHint(String hintName, Object value) {
		if ( isNotSelectForSure() ) {
			throw new IllegalArgumentException( "Result-caching is not relevant for non-select NativeQuery" );
		}
		super.applyResultCacheModeHint( hintName, value );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Fetch-size only applies to selecting queries; the query is a non-select native query.
  2. Remove the setFetchSize call for mutation native queries.

When it happens

Trigger: An API operation is invoked on a query object that does not support it.

Common situations: Calling query hint, locking, pagination, conversion, or mutation APIs on a query kind (native vs HQL, select vs mutation) that does not implement them.


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