hibernate/hibernate-orm · error · IllegalArgumentException
Invalid lock mode: WRITE
Error message
Invalid lock mode: WRITE
What it means
LoadEvent.validate() rejects LockMode.WRITE: this mode is reserved for Hibernate's internal write locking during flush and cannot be requested for a user-initiated load. The offending input is the lockOptions' lock mode.
Solutions
- Do not use LockMode.WRITE with load(); WRITE is reserved for internal use during insert/update.
- Use PESSIMISTIC_WRITE or another supported lock mode for explicit locking on load.
Defensive patterns
Strategy: validation
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/8ffb0ca875a2a236.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/event/spi/LoadEvent.java:90
super( source );
this.entityId = entityId;
this.entityClassName = entityClassName;
this.instanceToLoad = instanceToLoad;
this.lockOptions = lockOptions;
this.isAssociationFetch = isAssociationFetch;
this.readOnly = readOnly;
validate();
}
@Internal
public void validate() {
if ( entityId == null ) {
throw new IllegalArgumentException( "Identifier may not be null" );
}
final var lockMode = lockOptions.getLockMode();
if ( lockMode == LockMode.WRITE ) {
throw new IllegalArgumentException( "Invalid lock mode: " + LockMode.WRITE );
}
else if ( lockMode == null ) {
lockOptions.setLockMode( LockMode.NONE );
}
}
@Nonnull
public Object getEntityId() {
return entityId;
}
@Internal
public void setEntityId(@Nonnull Object entityId) {
this.entityId = entityId;
}
@Nullable
public String getEntityClassName() {View on GitHub (pinned to fad1729dce)