hibernate/hibernate-orm · error · IllegalStateException
Cannot call isReadOnlyBeforeAttachedToSession when…
Error message
Cannot call isReadOnlyBeforeAttachedToSession when isReadOnlySettingAvailable == true [{}#{}] What it means
Serialization-ordering guard in isReadOnlyBeforeAttachedToSession: this accessor is only legal when isReadOnlySettingAvailable() is false (i.e. during serialization of a detached proxy); calling it while the proxy is attached to an open session violates its contract. The faulty input is the call order; only invoke it during serialization when no session is attached.
Solutions
- Only call isReadOnlyBeforeAttachedToSession when the read-only setting is unavailable.
- Check isReadOnlySettingAvailable() first.
Defensive patterns
Strategy: validation
When it happens
Trigger: A runtime precondition of the Hibernate API is violated.
Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/62d7f57202d3ba8b.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java:450
}
}
/**
* Get the read-only/modifiable setting that should be put in effect when it is
* attached to a session.
* <p>
* This method should only be called during serialization when read-only/modifiable
* setting is not available, that is, if {@code isReadOnlySettingAvailable() == false}
*
* @return {@code null}, if the default setting should be used;
* {@code true}, for read-only;
* {@code false}, for modifiable
*
* @throws IllegalStateException if {@code isReadOnlySettingAvailable() == true}
*/
public final Boolean isReadOnlyBeforeAttachedToSession() {
if ( isReadOnlySettingAvailable() ) {
throw new IllegalStateException(
"Cannot call isReadOnlyBeforeAttachedToSession when isReadOnlySettingAvailable == true ["
+ entityName + "#" + id + "]"
);
}
return readOnlyBeforeAttachedToSession;
}
/**
* Get whether the proxy can load data even if it's not attached to a session
* with an ongoing transaction.
* <p>
* This method should only be called during serialization, and only makes sense
* after a call to {@link #prepareForPossibleLoadingOutsideTransaction()}.
*
* @return {@code true} if out-of-transaction loads are allowed,
* {@code false} otherwise.
*/
protected boolean isAllowLoadOutsideTransaction() {View on GitHub (pinned to fad1729dce)