配置里:
<property name="transactionAttributes">
<props>
<prop key="parseFile">PROPAGATION_NEVER</prop>
<prop key="netMap">PROPAGATION_NEVER</prop>
<prop key="dbInsert">PROPAGATION_REQUIRES_NEW,-Exception</prop>
</props>
</property>
我要拦截的方法是dbInsert
我的dbInsert函数体内容
...
Session session = getHibernateTemplate().getSessionFactory()
.getCurrentSession();
.....
// 执行SQL代码
session.createSQLQuery(colInfoBean.getChecksql().split("sqlfengefu")[k]).executeUpdate();
...........................
} catch (Exception e) {
。。。。。。。。。。。
}
我的想法是当出现Exception 异常时,更新操作回滚,但是现在不回滚,什么原因?
是不是和我的Session session = getHibernateTemplate().getSessionFactory()
.getCurrentSession();
这句话有关系,取当前的Session链接?
问题补充
我现在得解决办法是,不使用事务拦截器,直接在方法中进行事务管理了,这样可以解决问题。
问题是,为什么事务拦截器会不起作用呢,我不太明白。
问题补充:
如果不捕获异常,代码不让编译啊!
楼主,你都catch了应该不能回滚吧,spring只能回滚uncheck异常,
catch (Exception e) { }中加入TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
编码方式回滚,浸入性比较大
你不会向外抛异常吗,只有抛了
例如:dbInsert() throws Exception