google Analytics

Wednesday, July 7, 2010

Hibernate OnceperRequestFilter Example

OncePerRequestFilter Example:--

public class HibernateSessionFilter extends OncePerRequestFilter {

protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
Session session = null;
try {
SessionFactory sf = lookupSessionFactory(request);
session = sf.openSession(new DateEntryInterceptor());
}
private SessionFactory lookupSessionFactory(HttpServletRequest request) {
SessionFactory sf = null;
sf = (SessionFactory) getContext(request).getBean("stagingSessionFactory");
return sf;
}
public ApplicationContext getContext(HttpServletRequest httpRequest) {
return WebApplicationContextUtils.getRequiredWebApplicationContext(httpRequest.getSession().getServletContext());
}

}

1 comment:

  1. -- In Web.xml


    HibernateSessionFilter
    *.htm
    REQUEST

    ReplyDelete