hibernate/hibernate-orm · error · SessionException

Proxy for [{}#{}] is associated with a closed session (the r

Error message

Proxy for [{}#{}] is associated with a closed 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 associated with a closed 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:401

	 */
	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;
	}

	@Override
	public final void setReadOnly(boolean readOnly) {
		errorIfReadOnlySettingNotAvailable();
		// only update if readOnly is different from current setting
		if ( this.readOnly != readOnly ) {
			if ( !getEntityDescriptor().isMutable() && !readOnly ) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Reopen or obtain a new Session and reload the entity before setting read-only state.
  2. Perform read-only modifications before closing the session.

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