hibernate/hibernate-orm · error · LazyInitializationException
Could not initialize proxy [{}#{}] - session was closed or d
Error message
Could not initialize proxy [{}#{}] - session was closed or disconnected What it means
Error "Could not initialize proxy [{}#{}] - session was closed or disconnected" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java:262
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();
influencers.setTemporalIdentifier( temporalIdentifier );
try {
return session.immediateLoad( entityName, id );
}
finally {
influencers.setTemporalIdentifier( previous );
}
}
else {
return session.immediateLoad( entityName, id );View on GitHub (pinned to fad1729dce)
Solutions
- Initialize the proxy while the session is open and connected.
- Catch LazyInitializationException and reload within an active 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/e109fba45c9ff5cd.
Report an issue: GitHub.