Skip to content

Commit 6cca57a

Browse files
committed
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
1 parent 158b3c6 commit 6cca57a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

spring-orm/src/main/java/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ protected void doFilterInternal(
218218
closeSession(sessionHolder.getSession(), sessionFactory);
219219
}
220220
else {
221+
if (chain.isAsyncStarted()) {
222+
throw new IllegalStateException("Deferred close is not supported with async requests.");
223+
}
221224
// deferred close mode
222225
SessionFactoryUtils.processDeferredClose(sessionFactory);
223226
}

spring-orm/src/main/java/org/springframework/orm/hibernate3/support/OpenSessionInViewInterceptor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,13 @@ public Object call() throws Exception {
193193
*/
194194
public void postHandleAsyncStarted(WebRequest request) {
195195
String attributeName = getParticipateAttributeName();
196-
if ((request.getAttribute(attributeName, WebRequest.SCOPE_REQUEST) == null) && isSingleSession()) {
197-
TransactionSynchronizationManager.unbindResource(getSessionFactory());
196+
if (request.getAttribute(attributeName, WebRequest.SCOPE_REQUEST) == null) {
197+
if (isSingleSession()) {
198+
TransactionSynchronizationManager.unbindResource(getSessionFactory());
199+
}
200+
else {
201+
throw new IllegalStateException("Deferred close is not supported with async requests.");
202+
}
198203
}
199204
}
200205

0 commit comments

Comments
 (0)