hibernate/hibernate-orm · error · IllegalStateException

Cannot call isReadOnlyBeforeAttachedToSession when isReadOnl

Error message

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

What it means

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

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)

Solutions

  1. Only call isReadOnlyBeforeAttachedToSession when the read-only setting is unavailable.
  2. Check isReadOnlySettingAvailable() first.

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.