From 6cca57afd3912f5932bcfa512cca1d40ba125449 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 4 May 2012 18:58:47 -0400 Subject: [PATCH] Exception for OSIV deferred close with async requests OSIV deferred close mode is not supported with async requests and is unlikely to be what's the desired. This change adds an exception with a message stating this. Issue: SPR-8517 --- .../orm/hibernate3/support/OpenSessionInViewFilter.java | 3 +++ .../hibernate3/support/OpenSessionInViewInterceptor.java | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.java index fbcac64f644e..30cdc55f53b0 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.java @@ -218,6 +218,9 @@ protected void doFilterInternal( closeSession(sessionHolder.getSession(), sessionFactory); } else { + if (chain.isAsyncStarted()) { + throw new IllegalStateException("Deferred close is not supported with async requests."); + } // deferred close mode SessionFactoryUtils.processDeferredClose(sessionFactory); } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/OpenSessionInViewInterceptor.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/OpenSessionInViewInterceptor.java index 7fdd1518955b..5eccff677beb 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/OpenSessionInViewInterceptor.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/OpenSessionInViewInterceptor.java @@ -193,8 +193,13 @@ public Object call() throws Exception { */ public void postHandleAsyncStarted(WebRequest request) { String attributeName = getParticipateAttributeName(); - if ((request.getAttribute(attributeName, WebRequest.SCOPE_REQUEST) == null) && isSingleSession()) { - TransactionSynchronizationManager.unbindResource(getSessionFactory()); + if (request.getAttribute(attributeName, WebRequest.SCOPE_REQUEST) == null) { + if (isSingleSession()) { + TransactionSynchronizationManager.unbindResource(getSessionFactory()); + } + else { + throw new IllegalStateException("Deferred close is not supported with async requests."); + } } }