hibernate/hibernate-orm · error · IllegalArgumentException

Given LockModeType was null

Error message

Given LockModeType was null

What it means

Error "Given LockModeType was null" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:2203

	@Override
	@Nullable
	public <T> T find(
			@Nonnull Class<T> entityClass,
			@Nonnull Object primaryKey,
			@Nullable Map<String, Object> properties) {
		return doFind( entityClass, primaryKey, LockMode.NONE, properties );
	}

	@Override
	@Nullable
	public <T> T find(
			@Nonnull Class<T> entityClass,
			@Nonnull Object primaryKey,
			@Nonnull LockModeType lockModeType,
			@Nullable Map<String, Object> properties) {
		//noinspection ConstantValue
		if ( lockModeType == null ) {
			throw new IllegalArgumentException("Given LockModeType was null");
		}
		return doFind( entityClass, primaryKey, LockMode.fromJpaLockMode( lockModeType ), properties );
	}

	private <T> T doFind(Class<T> entityClass, Object primaryKey, LockMode lockMode, Map<String, Object> properties) {
		checkOpen();
		if ( entityClass == null ) {
			throw new IllegalArgumentException( "Entity class may not be null" );
		}
		final var options = determineFindOptions( lockMode, properties );
		final var entityDescriptor = requireEntityPersisterForLoad( entityClass );
		return byKeyWithGraph( entityClass, entityDescriptor, properties, options )
				.performFind( primaryKey );
	}

	private <T> FindByKeyOperation<T> byKeyWithGraph(
			Class<T> entityClass,
			EntityPersister entityDescriptor,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass a non-null LockModeType (e.g. LockModeType.PESSIMISTIC_READ) to the lock call.
  2. Guard against null when the lock mode is computed or passed from configuration.

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:2203 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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