使用OpenSessionInView (struts2 + hibernate)时,代码如下HibernateSessionFactory.getSession();
HibernateSessionFactory.openTransaction();
try {
chain.doFilter(request, response);
HibernateSessionFactory.commitTransaction();
} catch (Exception e) {
HibernateSessionFactory.RollbackTransaction();
e.printStackTrace();

} finally {
HibernateSessionFactory.closeSession();
}struts action 代码public String exe()throws Exception{
        throw new XXXException("xxxxx");
}这个时候 filter中应会捕获到异常再回滚才对,但并没有捕到。个人怀疑是因为struts2把我的异常给捕获了,但他没有往上抛给filter希望知道如何解决的,万分感谢啊

解决方案 »

  1.   

    跟openSessionInViewFilter一点关系也没有,建议你配置一下spring的事务管理
    并把你代码所以跟事务相关操作的代码都删掉
      

  2.   

    感谢你的回答,问题是我没有使用 Spring上面的代码也没有出现操作数据库的
    只是在action 中往上抛了个异常,我希望filter能够捕获到它
      

  3.   

    public String exe()throws Exception{
      throw new XXXException("xxxxx");
    }
     这样直接 throw一个异常是捕获不到的
      

  4.   

    public String exe()throws XXXException{
      throw new XXXException("xxxxx");
    }试一下这样,还有你确定他进了过滤器了
      

  5.   

    最有可能是struts2的拦截器给拦了,大家有没有办法?
      

  6.   


    既无spring,何来openSessionInViewFilter?
      

  7.   

    何来openSessionInViewFilter?
    哪位告诉你OOSV是Spring的东西,因为Spring管理了事务,所以它才出现在人们眼前而以,这是HibernateFilter里的改造过来的,几乎没有变化.
    似乎真是给Struts2拦截了.