hibernate/hibernate-orm · error · IllegalStateException

Proxy for [{}#{}] is not associated with a session (the read

Error message

Proxy for [{}#{}] is not associated with a session (the read-only/modifiable setting is only accessible when the proxy is associated with an open session)

What it means

Error "Proxy for [{}#{}] is not associated with a session (the read-only/modifiable setting is only accessible when the proxy is associated with an open session)" thrown in hibernate/hibernate-orm.

Source

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

	/**
	 * Getter for property "target".
	 * <p>
	 * Same as {@link #getImplementation()} except that this method will not force initialization.
	 *
	 * @return Value for property "target".
	 */
	protected final Object getTarget() {
		return target;
	}

	@Override
	public final boolean isReadOnlySettingAvailable() {
		return session != null && !session.isClosed();
	}

	private void errorIfReadOnlySettingNotAvailable() {
		if ( session == null ) {
			throw new IllegalStateException(
					"Proxy for [" + entityName + "#" + id + "] is not associated with a session"
							+ " (the read-only/modifiable setting is only accessible when the proxy is associated with an open session)"
			);
		}
		if ( !session.isOpenOrWaitingForAutoClose() ) {
			throw new SessionException(
					"Proxy for [" + entityName + "#" + id + "] is associated with a closed session"
							+ " (the read-only/modifiable setting is only accessible when the proxy is associated with an open session)"
			);
		}
	}

	@Override
	public final boolean isReadOnly() {
		errorIfReadOnlySettingNotAvailable();
		return readOnly;
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Associate the proxy with an open Session before changing read-only state.
  2. Set read-only state on the loaded entity within a session instead.

When it happens

Trigger: A lazy proxy is accessed outside the lifecycle of its owning Hibernate Session.

Common situations: LazyInitializationException-style failures when rendering entities after the transaction/Session closed, common in web views and serialization.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/0ad02cc19dfe3c10. Report an issue: GitHub.