读书人

解决session关闭时再调用对象方法时报

发布时间: 2013-04-09 16:45:09 作者: rapoo

解决session关闭时再调用对象方法时报session已关闭问题
private SessionFactory sf;//filter -- > public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { // sf.getCurrentSession();//获得和当前线程绑定的session sf.getCurrentSession().beginTransaction(); chain.doFilter(request, response); sf.getCurrentSession().getTransaction().commit(); } catch (StaleObjectStateException staleEx) { throw staleEx; } catch (Throwable ex) { ex.printStackTrace(); try { if (sf.getCurrentSession().getTransaction().isActive()) { sf.getCurrentSession().getTransaction().rollback(); } } catch (Throwable rbEx) { } throw new ServletException(ex); } } public void init(FilterConfig filterConfig) throws ServletException { sf = HibernateSessionFactory.getSessionFactory(); } public void destroy() { }

读书人网 >Web前端

热点推荐