In Hibernate in Action, the authors recommend
the following servlet filter for long sessions (chapter 8),
but in Hibernate 3.1, I get:
warning: reconnect() in org.hibernate.Session has been deprecated
what changed? Should I not use this, or use a different
reconnect()?
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
// Try to get a Hibernate Session from the HttpSession
HttpSession userSession =
((HttpServletRequest) request).getSession();
Session hibernateSession =
(Session) userSession.getAttribute("HibernateSession");
// and reconnect it to the current thread
if (hibernateSession != null)
HibernateUtil.reconnect(hibernateSession);
try {
chain.doFilter(request, response);
// Commit any pending database transaction.
HibernateUtil.commitTransaction();
} finally {
// Disconnect the Session
hibernateSession = HibernateUtil.disconnectSession();
// and store it in the user's HttpSession
userSession.setAttribute("HibernateSession", hibernateSession);
}
}
|