Hibernate version:
3.0.X
Servlet Filter
Code:
public class SessionManagerFilter implements Filter {
/**
* create a static reference to the logger.
*/
private static final Logger logger = Logger.getLogger(SessionManagerFilter.class);
private static final String FILTER_RUN = SessionManagerFilter.class.getName() + "FILTER_RUN";
/**
* Configures the filter.
*
* @param filterConfig the {@link javax.servlet.FilterConfig} to use.
* @throws javax.servlet.ServletException {@link javax.servlet.Filter} related problems.
*/
public void init(FilterConfig filterConfig) throws ServletException {
logger.debug("init - start");
logger.debug("init - end");
}
/**
* Shuts down the filter.
*/
public void destroy() {
logger.debug("destroy - start");
logger.debug("destroy - end");
}
/**
* Executes the filter.
*
* @param servletRequest the {@link ServletRequest} to use.
* @param servletResponse the {@link ServletResponse} to use.
* @param filterChain the {@link FilterChain} to use.
* @throws IOException I/O related problems.
* @throws ServletException {@link Servlet} related problems.
*/
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
logger.debug("doFilter - start");
try {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
HttpSession session = request.getSession();
Boolean filterRun = (Boolean) session.getAttribute(FILTER_RUN);
if (filterRun != null && filterRun.booleanValue()) {
filterChain.doFilter(request, response);
} else {
// do the rest of the filter chain
session.setAttribute(FILTER_RUN, Boolean.TRUE);
filterChain.doFilter(request, response);
if (session != null && !session.isNew()) {
session.removeAttribute(FILTER_RUN);
}
}
} catch (Exception e) {
logger.fatal(e.getMessage(), e);
throw new ServletException(e.getMessage(), e);
} finally {
try {
HibernateHelper.closeSession();
} catch (Exception e) {
throw new ServletException(e.getMessage(), e);
} finally {
logger.debug("doFilter - end");
}
}
}
}
Full stack trace of any exception that occurs:
[ERROR] [10 Jun 2005 16:42:44.468] [LazyInitializationException] [could not initialize proxy - the owning Session was closed]
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
Name and version of the database you are using:
MySQL 4.1.X
The generated SQL (show_sql=true):
Problem:
When using the
http://www.hibernate.org/43.html - Open Session in View pattern, is there a way to get around having not having an session open on the JSP?
When I attempt to modify objects in my JSP I am getting a session is disconnected exception.