请问spring事务控制回滚的有关问题

请教spring事务控制回滚的问题
问一下:
[color=orange]
<tx:advice id="txAdvice" transaction-manager="txManager">
  <tx:attributes>
    <tx:method name="get*" read-only="false" rollback-for="NoProductInStockException"/>
    <tx:method name="*"/>
  </tx:attributes>
</tx:advice>

[/color]

这里的NoProductInStockException是在那里抛出的?dao层还是service层啊?
1 楼 webmaster 2008-02-21  
armorking 写道
<tx:method name="get*" read-only="false" rollback-for="NoProductInStockException"/>
这句话的意思是:
当service中的所有以“get”开头的public method在处理中发生异常的时,
最后被抛出的异常的类型是“NoProductInStockException”的时候,作rollback

spring默认uncheckedException、RuntimeException时rollback,设置这个rollback-for="SomeException"后,对于uncheckedException、RuntimeException还rollback吗?

还有我想知道的是  NoProductInStockException 这个Exception是 checked 还是unchecked的啊?
是在dao、service那一层 throw呢?
2 楼 lizwjiang 2008-02-22  
webmaster 写道
armorking 写道
<tx:method name="get*" read-only="false" rollback-for="NoProductInStockException"/>
这句话的意思是:
当service中的所有以“get”开头的public method在处理中发生异常的时,
最后被抛出的异常的类型是“NoProductInStockException”的时候,作rollback

spring默认uncheckedException、RuntimeException时rollback,设置这个rollback-for="SomeException"后,对于uncheckedException、RuntimeException还rollback吗?

还有我想知道的是  NoProductInStockException 这个Exception是 checked 还是unchecked的啊?
是在dao、service那一层 throw呢?



对于uncheckedException、RuntimeException还rollback吗? 是的,还是会rollback

是checked还是unchecked你需要看看这个异常类继承的Class是什么,至于在那层throw,那层发生异常就在那层throw阿。

建议楼主补一下基础

3 楼 andycui 2008-02-22  
由spring来控制事务以后,它会生成代理类来包装你的service层对象,所以不管这个NoProductInStockException在哪一层抛出的,最后都会被spring生成的代理类所捕获,捕获后如果是runtime异常就会回滚,同时由于你配置了rollback-for="NoProductInStockException",不管这个NoProductInStockException是checked还是unchecked异常,都会被自动回滚。

代理类的生成是通过JDK1.4的Proxy或者CGLIB生成的
4 楼 skydream 2008-02-22  
楼主的id很强,我正奇怪javaeye怎么没有保留这些id关键字呢?
5 楼 lggege 2008-02-22  
哈哈. Advisor 就是指 AOP具体要执行的事情.

依你的配置, 你应该只配置了一个Advisor, 而没有配置Pointcut. 也就是谁要被通知你没有定义.你应该还有下面的一段代码才对.

<aop:config>
	<aop:pointcut id="iwooServicePointcut" expression="execution(* cn.iwoo.server.service.*.*(..))"/>
		<aop:advisor pointcut-ref="iwooServicePointcut" advice-ref="txAdvice"/>
</aop:config>


这样配置了以后,你就很明白了,你的pointcut是谁,就是谁抛的异常.