PROPAGATION_REQUIRES_NEW VS PROPAGATION_NESTED

PROPAGATION_REQUIRES_NEW, in contrast to PROPAGATION_REQUIRED, uses a completely independent transaction for each affected transaction scope. In that case,

the underlying physical transactions are different and hence can commit or roll back independently, with an outer transaction not affected by an inner transaction’s

rollback status.

PROPAGATION_NESTED uses a single physical transaction with multiple savepoints that it can roll back to. Such partial rollbacks allow an inner transaction scope to

trigger a rollback for its scope, with the outer transaction being able to continue the physical transaction despite some operations having been rolled back. This

setting is typically mapped onto JDBC savepoints, so will only work with JDBC resource transactions. See Spring’s DataSourceTransactionManager.

PROPAGATION_NESTED是 Spring 所特有的。以 PROPAGATION_NESTED 启动的事务内嵌于外部事务中(如果存在外部事务的话),此时,内嵌事务并不是一个独立的事务,

它依赖于外部事务的存在,只有通过外部的事务提交,才能引起内部事务的提交,嵌套的子事务不能单独提交。如果熟悉 JDBC 中的保存点(SavePoint)的概念,那嵌套事务就

很容易理解了,其实嵌套的子事务就是保存点的一个应用,一个事务中可以包括多个保存点,每一个嵌套子事务。另外,外部事务的回滚也会导致嵌套子事务的回滚。

出处:

spring propagation_requires_new VS propagation_nested

参考:

IBM developerWork : 全面分析 Spring 的编程式事务管理及声明式事务管理

importNew: savePoint示例

上一篇:win10上VMare安装Centos7并使用Xshell连接Centos


下一篇:Spark排错与优化