Spring嵌套事务机制补充
上一篇文章,是关于Spring嵌套事务机制的,回过头来看发现有不少问题,但暂时不想删掉它,所以再写一篇文章更正一下之前的错误。这里先再次说明一下PROPAGATION_NESTED的作用,若当前存在事务则以嵌套事务方式执行,若不存在事务则创建一个新事务。
上一篇文章,是关于Spring嵌套事务机制的,回过头来看发现有不少问题,但暂时不想删掉它,所以再写一篇文章更正一下之前的错误。这里先再次说明一下PROPAGATION_NESTED的作用,若当前存在事务则以嵌套事务方式执行,若不存在事务则创建一个新事务。
Spring的几种事务传播机制如下:
PROPAGATION_REQUIRED:Support a current transaction, create a new one if none exists.
PROPAGATION_SUPPORTS:Support a current transaction, execute non-transactionally if none exists.
PROPAGATION_MANDATORY:Support a current transaction, throw an exception if none exists.
PROPAGATION_REQUIRES_NEW:Create a new transaction, and suspend the current transaction if one exists.
PROPAGATION_NOT_SUPPORTED:Execute non-transactionally, suspend the current transaction if one exists.
PROPAGATION_NEVER:Execute non-transactionally, throw an exception if a transaction exists.
PROPAGATION_NESTED:Execute within a nested transaction if a current transaction exists, behave like PROPAGATION_REQUIRED.