hibernate/hibernate-orm · error · IllegalStateException

Lock timeout not supported for native query

Error message

Lock timeout not supported for native query

What it means

IllegalStateException from setLockTimeout on a native query: lock timeouts cannot be applied to native SQL queries.

Solutions

  1. Lock timeouts are not supported on native queries.
  2. Remove the lock-timeout hint or set the timeout at the JDBC/transaction level.
Defensive patterns

Strategy: validation

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.

Understand the failure class


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

Appendix: source

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

	@Override
	@Nonnull
	public NativeQueryImplementor<R> setHibernateLockMode(@Nonnull LockMode lockMode) {
		//noinspection removal
		queryOptions.getLockOptions().setLockMode( lockMode );
		return this;
	}

	@Override
	@Nullable
	public Timeout getLockTimeout() {
		return null;
	}

	@Override
	@Nonnull
	public NativeQueryImplementor<R> setLockTimeout(@Nullable Timeout lockTimeout) {
		throw new IllegalStateException( "Lock timeout not supported for native query" );
	}

	@Override
	@Nonnull
	public NativeQueryImplementor<R> setLockScope(@Nonnull PessimisticLockScope lockScope) {
		//noinspection removal
		queryOptions.getLockOptions().setLockScope( lockScope );
		return this;
	}

	@Override @Deprecated
	@SuppressWarnings("removal")
	@Nonnull
	public NativeQueryImplementor<R> disableFetchProfile(@Nonnull String profileName) {
		queryOptions.disableFetchProfile( profileName );
		return this;
	}

View on GitHub (pinned to fad1729dce)