How are others handling the situation were a user sends a request in and before that request can finish, causes another request to be sent? We are using long transactions with reconnect and have a filter doing the dis/re-connecting. Our stop gap solution was to synchronized the filter (see code below), including the chain.doFilter. Obviously, we need a better solution. Thanks for any help,
Jeff
Code:
try {
synchronized (request.getSession()) {
ThreadObjectManager threadObjectManager =
SessionFactoryUtils.getThreadObjectManager();
if (threadObjectManager.hasThreadObject(sessionFactory)) {
threadObjectManager.removeThreadObject(sessionFactory);
}
Session session =
(Session) request.getSession().getAttribute(
HIBERNATE_SESSION_KEY);
if (session != null) {
session.reconnect();
}
else {
session = sessionFactory.openSession();
request.getSession().setAttribute(
HIBERNATE_SESSION_KEY,
session);
}
threadObjectManager.bindThreadObject(
sessionFactory,
new SessionHolder(session));
try {
chain.doFilter(request, response);
} finally {
try {
session.disconnect();
}
catch (HibernateException e) {
log.warn(e);
}
}
}
}