hibernate/hibernate-orm · error · LazyInitializationException

Could not initialize proxy

Error message

Could not initialize proxy [{}#{}] - no session

What it means

LazyInitializationException from initialize(): the proxy is uninitialized and its session reference is null (unsetSession was called, e.g. after detach or serialization), so the target cannot be loaded. The faulty state is a detached uninitialized proxy; reattach it to an open session before accessing it.

Solutions

  1. Initialize the proxy while its owning Session is still open (Hibernate.initialize or access within the session).
  2. Enable Open Session in View or fetch eagerly if data is needed outside the 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/acd1c71c5208617a. Report an issue: GitHub.

Appendix: source

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

	}

	@Override
	public final void unsetSession() {
		prepareForPossibleLoadingOutsideTransaction();
		session = null;
		readOnly = false;
		readOnlyBeforeAttachedToSession = null;
	}

	@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() ) {

View on GitHub (pinned to fad1729dce)