hibernate/hibernate-orm · error · IllegalArgumentException

Locking is not relevant for non-select NativeQuery

Error message

Locking is not relevant for non-select NativeQuery

What it means

Error "Locking 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:966

	}

	@Override
	protected void applyEntityGraphHint(GraphSemantic graphSemantic, Object value, String hintName) {
		throw new HibernateException( "A native SQL query cannot use EntityGraphs" );
	}

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

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

	@Override
	protected void applyFollowOnStrategyHint(Object value) {
		if ( isNotSelectForSure() ) {
			throw new IllegalArgumentException( "Locking is not relevant for non-select NativeQuery" );
		}
		super.applyFollowOnStrategyHint( value );
	}

	@Override
	@Nonnull
	public <T> NativeQueryImplementor<T> setTupleTransformer(@Nonnull TupleTransformer<T> transformer) {
		errorIfNotSelectForSure();
		queryOptions.setTupleTransformer( transformer );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Locking options only apply to selecting queries; the query is a non-select native query.
  2. Remove lock-related options 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/8583ad0648231fc9. Report an issue: GitHub.