hibernate/hibernate-orm · error · IllegalArgumentException
Skip-locked is not valid option for #lock
Error message
Skip-locked is not valid option for #lock
What it means
Error "Skip-locked is not valid option for #lock" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/event/spi/LockEvent.java:39
public class LockEvent extends AbstractSessionEvent {
public static final String ILLEGAL_SKIP_LOCKED = "Skip-locked is not valid option for #lock";
private Object object;
private final LockOptions lockOptions;
private String entityName;
public LockEvent(@Nullable String entityName, @Nonnull Object object, @Nonnull LockOptions lockOptions, @Nonnull EventSource source) {
super(source);
if (object == null) {
throw new IllegalArgumentException( "Entity may not be null" );
}
if (lockOptions == null) {
throw new IllegalArgumentException( "LockOptions may not be null" );
}
if ( lockOptions.getLockMode() == LockMode.UPGRADE_SKIPLOCKED
|| lockOptions.getTimeout().milliseconds() == Timeouts.SKIP_LOCKED_MILLI ) {
throw new IllegalArgumentException( ILLEGAL_SKIP_LOCKED );
}
this.entityName = entityName;
this.object = object;
this.lockOptions = lockOptions;
}
public LockEvent(@Nonnull Object object, @Nonnull LockOptions lockOptions, @Nonnull EventSource source) {
this( null, object, lockOptions, source );
}
/**
* @deprecated Use {@linkplain LockEvent#LockEvent(Object, LockOptions, EventSource)} instead.
*/
@Deprecated(since = "7", forRemoval = true)
public LockEvent(@Nonnull Object object, @Nonnull LockMode lockMode, @Nonnull EventSource source) {
this( object, lockMode.toLockOptions(), source );
}View on GitHub (pinned to fad1729dce)
Solutions
- Remove LockOptions.setSkipLocked(true) when using Session.lock(); skip-locked is only valid for queries.
- Apply skip-locked via query hints or Query.setLockOptions on a selection query instead.
When it happens
Trigger: Thrown when SKIP_LOCKED is requested for an operation that does not support it.
Common situations: Typical situations: applying lock options intended for queries to a #lock call; dialect/feature mismatch for skip-locked.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/b0032a4eb1a3027d.
Report an issue: GitHub.