hibernate/hibernate-orm · error · LazyInitializationException

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

Error message

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

What it means

Error "Could not initialize proxy [{}#{}] - no session" thrown in hibernate/hibernate-orm.

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)

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.

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.