hibernate/hibernate-orm · error · IllegalArgumentException
Invalid lock mode '${lockMode}' passed to 'lock()'
Error message
Invalid lock mode '${lockMode}' passed to 'lock()' What it means
Error "Invalid lock mode '${lockMode}' passed to 'lock()'" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLockEventListener.java:41
public class DefaultLockEventListener implements LockEventListener {
/**
* Handle the given lock event.
*
* @param event The lock event to be handled.
*/
@Override
public void onLock(@Nonnull LockEvent event) {
final Object instance = event.getObject();
//noinspection ConstantValue
if ( instance == null ) {
throw new NullPointerException( "Attempted to lock null" );
}
final var lockMode = event.getLockMode();
if ( lockMode == LockMode.WRITE || lockMode == LockMode.UPGRADE_SKIPLOCKED ) {
throw new IllegalArgumentException( "Invalid lock mode '" + lockMode + "' passed to 'lock()'" );
}
final var source = event.getSession();
final Object entity = forceInitialize( instance, source );
//TODO: if instance was an uninitialized proxy, this is inefficient,
// resulting in two SQL selects
final var entry = source.getPersistenceContextInternal().getEntry( entity );
if ( entry == null && instance == entity ) {
throw new DetachedObjectException( "Given entity is not associated with the persistence context" );
}
assert entry != null;
upgradeLock( entity, entry, event.getLockOptions(), source );
}
}
View on GitHub (pinned to fad1729dce)
Solutions
- Pass a valid LockMode value (e.g. NONE, READ, PESSIMISTIC_READ, PESSIMISTIC_WRITE) to lock().
- Verify the LockMode comes from the org.hibernate.LockMode enum rather than an arbitrary string.
When it happens
Trigger: Thrown when an unsupported LockMode is supplied for the attempted lock operation.
Common situations: Typical situations: passing LockMode.WRITE where it is not permitted; a lock mode computed from user input without validation.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/01cea3e052899fe7.
Report an issue: GitHub.