spring事务传播

REQUIRED

Support a current transaction, create a new one if none exists.
支持外层事务, 如果不存在外层事务则创建一个新事务; 当前事务和外层事务一块提交一块回滚(一起)

REQUIRES_NEW

Create a new transaction, and suspend the current transaction if one exists.
创建一个新事务, 如果存在外层事务则把外层事务挂起; 当前事务执行完成后再执行外层事务(各顾各的)

SUPPORTS

Support a current transaction, execute non-transactionally if none exists.
支持外层事务, 如果存在外层事务则跟外层事务一块执行, 如果不存在外层事务就以非事务方式执行 (有则加入, 无则非事务)

NOT_SUPPORTED

Execute non-transactionally, suspend the current transaction if one exists.
不支持外层事务, 如果存在外层事务则把外层事务挂起, 执行完当前代码再恢复外层事务

MANDATORY

Support a current transaction, throw an exception if none exists.
支持外层事务, 如果不存在外层事务则抛出异常

NEVER

Execute non-transactionally, throw an exception if a transaction exists.
不支持外层事务, 如果存在外层事务则抛出异常

NESTED

Execute within a nested transaction if a current transaction exists, behave like REQUIRED otherwise
支持外层事务, 当前事务嵌套在外层事务中执行; 外层事务回滚,当前事务也会回滚; 当前事务回滚,不会影响外层事务

NESTED和REQUIRES_NEW的区别

REQUIRES_NEW: 当前事务先提交, 外层事务后提交; 由于外层事务没提交时当前事务已经提交了, 所以可能导致脏读问题
NESTED: 当前事务会跟外层事务一块提交
参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值