hibernate/hibernate-orm · error · IllegalStateException

Cannot call afterDeserialization when isReadOnlySettingAvail

Error message

Cannot call afterDeserialization when isReadOnlySettingAvailable == true [{}#{}]

What it means

Error "Cannot call afterDeserialization when isReadOnlySettingAvailable == true [{}#{}]" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java:517

	 * <p>
	 * This method should only be called during deserialization, before associating
	 * the proxy with a session.
	 *
	 * @param readOnlyBeforeAttachedToSession the read-only/modifiable setting to
	 *        use when associated with a session; null indicates that the default
	 *        should be used.
	 * @param sessionFactoryUuid the session factory uuid, to be used if
	 *        {@code allowLoadOutsideTransaction} is {@code true}.
	 * @param allowLoadOutsideTransaction whether the proxy can load data even
	 * if it's not attached to a session with an ongoing transaction.
	 *
	 * @throws IllegalStateException if {@code isReadOnlySettingAvailable() == true}
	 */
	/* package-private */
	final void afterDeserialization(Boolean readOnlyBeforeAttachedToSession,
			String sessionFactoryUuid, String sessionFactoryName, boolean allowLoadOutsideTransaction) {
		if ( isReadOnlySettingAvailable() ) {
			throw new IllegalStateException(
					"Cannot call afterDeserialization when isReadOnlySettingAvailable == true ["
							+ entityName + "#" + id + "]"
			);
		}
		this.readOnlyBeforeAttachedToSession = readOnlyBeforeAttachedToSession;
		this.sessionFactoryUuid = sessionFactoryUuid;
		this.sessionFactoryName = sessionFactoryName;
		this.allowLoadOutsideTransaction = allowLoadOutsideTransaction;
	}

	@Override
	public boolean isUnwrap() {
		return unwrap;
	}

	@Override
	public void setUnwrap(boolean unwrap) {
		this.unwrap = unwrap;

View on GitHub (pinned to fad1729dce)

Solutions

  1. Call afterDeserialization only on proxies whose read-only setting is not already available.
  2. Follow the documented proxy deserialization lifecycle.

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/a7ab143eb275c77f. Report an issue: GitHub.