最近学习spring的aop声明式事务管理,发现一个奇怪的问题,xml部分配置贴出来:
<tx:advice id="hibernateAdvice">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(* com.bjsxt.drp.basedata.Manager.ItemManager.*(..))" id="hibernatePointcut"/>
<aop:advisor advice-ref="hibernateAdvice" pointcut-ref="hibernatePointcut"/>
</aop:config>ItemManager中的add方法: public void addItem(Item item) { getHibernateTemplate().save(item);
// throw new RuntimeException(); }测试发现事务的自动开启和提交没问题,但如果显式的抛出运行时异常,item的插入数据不会自动回滚,纠结了好几个小时,尝试过许多方法都无效,百思不得其解啊
<tx:advice id="hibernateAdvice">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(* com.bjsxt.drp.basedata.Manager.ItemManager.*(..))" id="hibernatePointcut"/>
<aop:advisor advice-ref="hibernateAdvice" pointcut-ref="hibernatePointcut"/>
</aop:config>ItemManager中的add方法: public void addItem(Item item) { getHibernateTemplate().save(item);
// throw new RuntimeException(); }测试发现事务的自动开启和提交没问题,但如果显式的抛出运行时异常,item的插入数据不会自动回滚,纠结了好几个小时,尝试过许多方法都无效,百思不得其解啊
解决方案 »
- 这问题困扰了半天了,关于Servlet的。
- 关于进程
- 看了这道题你就知道中国大学和美国大学差什么了(委托和继承)
- SessionBean中封装的业务逻辑,如何在Struct中调用SessionBean,而SessionBean调用EntityBean?
- 如何写一个单独的线程处理某个方法
- servlet forward sendRedirect怎么都不跳转和冲定向?
- 请教一个关于java的很菜的问题
- EJB部署到JBuilder7时有如下错误,怎样解决呢?
- 有人用jrun吗???交个朋友
- myeclipse10整合ssh框架时发生Error occured processing XML 'Provider org.apache.xer。。。。
- java 调用window API问题!
- 查询字数限制问题???
上面的配置应该没有错误,我想到了一种可能,就是ItemManager你没有交给spring管理,也就是说你在使用这个类型的时候,ItemManager的初始化工作你是手动new的,而不是采用内部机制初始化的,这样你的事物是不起作用的。