使用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希望知道如何解决的,万分感谢啊
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希望知道如何解决的,万分感谢啊
并把你代码所以跟事务相关操作的代码都删掉
只是在action 中往上抛了个异常,我希望filter能够捕获到它
throw new XXXException("xxxxx");
}
这样直接 throw一个异常是捕获不到的
throw new XXXException("xxxxx");
}试一下这样,还有你确定他进了过滤器了
既无spring,何来openSessionInViewFilter?
哪位告诉你OOSV是Spring的东西,因为Spring管理了事务,所以它才出现在人们眼前而以,这是HibernateFilter里的改造过来的,几乎没有变化.
似乎真是给Struts2拦截了.