hibernate/hibernate-orm · error · LazyInitializationException
Could not initialize proxy [{}#{}] - the owning session was
Error message
Could not initialize proxy [{}#{}] - the owning session was closed What it means
Error "Could not initialize proxy [{}#{}] - the owning session was closed" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java:182
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() ) {
session.getJdbcCoordinator().afterTransaction();
}
}
}View on GitHub (pinned to fad1729dce)
Solutions
- Initialize the proxy before closing the owning Session.
- Reattach the entity to a new Session via merge/load before accessing lazy state.
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/87d3aa7953c4c94f.
Report an issue: GitHub.