From e07f1aa89b4856b2127e19e9c19cdeeebbe27244 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Tue, 8 Jan 2019 08:56:48 -0500 Subject: [PATCH] HHH-13191 - Avoid LazyInitializationException when session is waiting for auto-close with JPA_PROXY_COMPLIANCE enabled. --- .../java/org/hibernate/proxy/AbstractLazyInitializer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java b/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java index be5b30b371..acb63cc4b2 100644 --- a/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java @@ -168,7 +168,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer { else if ( session == null ) { throw new LazyInitializationException( "could not initialize proxy [" + entityName + "#" + id + "] - no Session" ); } - else if ( !session.isOpen() ) { + else if ( !session.isOpenOrWaitingForAutoClose() ) { throw new LazyInitializationException( "could not initialize proxy [" + entityName + "#" + id + "] - the owning Session was closed" ); } else if ( !session.isConnected() ) { @@ -344,7 +344,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer { "Proxy [" + entityName + "#" + id + "] is detached (i.e, session is null). The read-only/modifiable setting is only accessible when the proxy is associated with an open session." ); } - if ( session.isClosed() ) { + if ( !session.isOpenOrWaitingForAutoClose() ) { throw new SessionException( "Session is closed. The read-only/modifiable setting is only accessible when the proxy [" + entityName + "#" + id + "] is associated with an open session." );