hibernate/hibernate-orm · error · LazyInitializationException

Could not initialize proxy

Error message

Could not initialize proxy [{}#{}]: {}

What it means

LazyInitializationException from permissiveInitialization (allowLoadOutsideTransaction path): the temporary session used to load the proxy outside a transaction failed with some exception, which is wrapped here. The original cause is in the message/cause; fix the underlying load failure (e.g. missing row was deleted) rather than this wrapper.

Solutions

  1. Inspect the nested cause for the real initialization failure (e.g. missing row, connection error).
  2. Verify the entity row still exists in the database.
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/79101d8f288b767b. Report an issue: GitHub.

Appendix: source

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

					target = immediateLoad( session );
					initialized = true;
					checkTargetState( session );
				}
				finally {
					// make sure the just opened temp session gets closed!
					try {
						if ( !isJTA ) {
							session.getTransaction().commit();
						}
						session.close();
					}
					catch (Exception e) {
						CORE_LOGGER.unableToCLoseTempSession();
					}
				}
			}
			catch (Exception e) {
				throw new LazyInitializationException( "Could not initialize proxy ["
						+ entityName + "#" + id + "]: " + e.getMessage() );
			}
		}
		else if ( session.isOpenOrWaitingForAutoClose() && session.isConnected() ) {
			target = immediateLoad( session );
			initialized = true;
			checkTargetState( session );
		}
		else {
			throw new LazyInitializationException( "Could not initialize proxy ["
					+ entityName + "#" + id + "] - session was closed or disconnected" );
		}
	}

	private Object immediateLoad(SharedSessionContractImplementor session) {
		if ( temporalIdentifier != null ) {
			final var influencers = session.getLoadQueryInfluencers();
			final Object previous = influencers.getTemporalIdentifier();

View on GitHub (pinned to fad1729dce)