spring的事务传播机制(propagation)
spring的事物传播机制分为7种:
1.required
2.requires new
3.supports
4.not supportted
5.nested
6.mandatory
7.never
用法说明在jar包spring-tx的org.springframework.transaction.annotation.Propagation类中.
只说两个容易混淆的:requires new 和 nested,其他看注释。
这两种机制共同点是:
内层事务出错回滚时,外层代码如果catch到错误仍然可以选择继续执行。
最大的区别是 :
requires new会在内层db操作开始时新建一个事务,此事务与外层事务完全独立,外层如果出错回滚,内层仍然会提交;
而nested从始至终只有一个事务,只是会在内层db操作开始时新建一个savePoint,所以外层如果回滚,则内层必然回滚,因为它们是同一个事务。