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: 当前事务会跟外层事务一块提交
参考