hibernate/hibernate-orm · error · IllegalStateException

Cannot make proxy [{}#{}] for immutable entity modifiable

Error message

Cannot make proxy [{}#{}] for immutable entity modifiable

What it means

Error "Cannot make proxy [{}#{}] for immutable entity modifiable" thrown in hibernate/hibernate-orm.

Source

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

					"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 ) {
				throw new IllegalStateException( "Cannot make proxy [" + entityName + "#" + id + "] for immutable entity modifiable" );
			}
			this.readOnly = readOnly;
			if ( initialized ) {
				final var key = generateEntityKeyOrNull( getInternalIdentifier(), session, getEntityName() );
				if ( key != null ) {
					final var persistenceContext = session.getPersistenceContext();
					if ( persistenceContext.containsEntity( key ) ) {
						persistenceContext.setReadOnly( target, readOnly );
					}
				}
			}
		}
	}

	/**
	 * Get the read-only/modifiable setting that should be put in effect when it is
	 * attached to a session.
	 * <p>

View on GitHub (pinned to fad1729dce)

Solutions

  1. Do not attempt to make proxies of @Immutable entities modifiable.
  2. Remove the @Immutable annotation if mutation is required.

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