hibernate/hibernate-orm · error · LazyInitializationException

Could not initialize proxy

Error message

Could not initialize proxy [{}#{}] - the owning session is disconnected

What it means

LazyInitializationException from initialize(): the owning session is still notionally open but isConnected() is false, i.e. it is disconnected from its JDBC connection/transaction, so lazy loading cannot proceed. The faulty state is an uninitialized proxy on a disconnected session; reconnect the session or initialize within an active transaction.

Solutions

  1. Reconnect the Session before initializing the proxy.
  2. Load the entity fresh in a connected session.
Defensive patterns

Strategy: try-catch

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

Appendix: source

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

	}

	@Override
	public final void initialize() throws HibernateException {
		if ( !initialized ) {
			try {
				if ( allowLoadOutsideTransaction ) {
					permissiveInitialization();
				}
				else if ( session == null ) {
					throw new LazyInitializationException( "Could not initialize proxy ["
							+ entityName + "#" + id + "] - no session" );
				}
				else if ( !session.isOpenOrWaitingForAutoClose() ) {
					throw new LazyInitializationException( "Could not initialize proxy ["
							+ entityName + "#" + id + "] - the owning session was closed" );
				}
				else if ( !session.isConnected() ) {
					throw new LazyInitializationException( "Could not initialize proxy ["
							+ entityName + "#" + id + "] - the owning session is disconnected" );
				}
				else {
					target = immediateLoad( session );
					initialized = true;
					checkTargetState( session );
				}
			}
			finally {
				if ( session != null && !session.isTransactionInProgress() ) {
					session.getJdbcCoordinator().afterTransaction();
				}
			}
		}
		else {
			checkTargetState( session );
		}
	}

View on GitHub (pinned to fad1729dce)