HHH-13191 - Avoid LazyInitializationException when session is waiting for auto-close with JPA_PROXY_COMPLIANCE enabled
This commit is contained in:
parent
e07f1aa89b
commit
53c589a9e1
|
@ -232,7 +232,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
|
||||||
throw new LazyInitializationException( e.getMessage() );
|
throw new LazyInitializationException( e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( session.isOpen() && session.isConnected() ) {
|
else if ( session.isOpenOrWaitingForAutoClose() && session.isConnected() ) {
|
||||||
target = session.immediateLoad( entityName, id );
|
target = session.immediateLoad( entityName, id );
|
||||||
initialized = true;
|
initialized = true;
|
||||||
checkTargetState(session);
|
checkTargetState(session);
|
||||||
|
@ -250,7 +250,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
|
||||||
* of that session since the proxy was created.
|
* of that session since the proxy was created.
|
||||||
*/
|
*/
|
||||||
public final void initializeWithoutLoadIfPossible() {
|
public final void initializeWithoutLoadIfPossible() {
|
||||||
if ( !initialized && session != null && session.isOpen() ) {
|
if ( !initialized && session != null && session.isOpenOrWaitingForAutoClose() ) {
|
||||||
final EntityKey key = session.generateEntityKey(
|
final EntityKey key = session.generateEntityKey(
|
||||||
getIdentifier(),
|
getIdentifier(),
|
||||||
session.getFactory().getMetamodel().entityPersister( getEntityName() )
|
session.getFactory().getMetamodel().entityPersister( getEntityName() )
|
||||||
|
@ -298,7 +298,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
|
||||||
|
|
||||||
private Object getProxyOrNull() {
|
private Object getProxyOrNull() {
|
||||||
final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), session, getEntityName() );
|
final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), session, getEntityName() );
|
||||||
if ( entityKey != null && session != null && session.isOpen() ) {
|
if ( entityKey != null && session != null && session.isOpenOrWaitingForAutoClose() ) {
|
||||||
return session.getPersistenceContext().getProxy( entityKey );
|
return session.getPersistenceContext().getProxy( entityKey );
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue