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
This commit is contained in:
Rossen Stoyanchev 2012-05-04 18:58:47 -04:00
parent 158b3c6af8
commit 6cca57afd3
2 changed files with 10 additions and 2 deletions

View File

@ -218,6 +218,9 @@ public class OpenSessionInViewFilter extends OncePerRequestFilter {
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);
}

View File

@ -193,8 +193,13 @@ public class OpenSessionInViewInterceptor extends HibernateAccessor implements A
*/
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.");
}
}
}