javascript
Spring事务传播
2019獨角獸企業重金招聘Python工程師標準>>>
事務傳播在org.springframework.transaction.TransactionDefinition中定義
PROPAGATION_REQUIRED
Support a current transaction; create a new one if none exists. Analogous to the EJB transaction attribute of the same name.
This is typically the default setting of a transaction definition, and typically defines a transaction synchronization scope.
支持當前事務。如果當前沒有事務則創建一個新的事務。
這是事務定義的默認設置,并且定義了一個典型的事務同步域。
PROPAGATION_SUPPORTS
Support a current transaction; execute non-transactionally if none exists. Analogous to the EJB transaction attribute of the same name.
NOTE: For transaction managers with transaction synchronization, PROPAGATION_SUPPORTS is slightly different from no transaction at all, as it defines a transaction scope that synchronization might apply to. As a consequence, the same resources (a JDBC Connection, a Hibernate Session, etc) will be shared for the entire specified scope. Note that the exact behavior depends on the actual synchronization configuration of the transaction manager!
In general, use PROPAGATION_SUPPORTS with care! In particular, do not rely on PROPAGATION_REQUIRED or PROPAGATION_REQUIRES_NEW within a PROPAGATION_SUPPORTS scope (which may lead to synchronization conflicts at runtime). If such nesting is unavoidable, make sure to configure your transaction manager appropriately (typically switching to "synchronization on actual transaction").
支持當前事務。如果當前沒有的話就以非事務方式執行。
PROPAGATION_MANDATORY
Support a current transaction; throw an exception if no current transaction exists. Analogous to the EJB transaction attribute of the same name.
Note that transaction synchronization within a PROPAGATION_MANDATORY scope will always be driven by the surrounding transaction.
支持當前事務,如果當前不存在事務,就拋異常。
PROPAGATION_REQUIRES_NEW
Create a new transaction, suspending the current transaction if one exists. Analogous to the EJB transaction attribute of the same name.
NOTE: Actual transaction suspension will not work out-of-the-box on all transaction managers. This in particular applies to org.springframework.transaction.jta.JtaTransactionManager, which requires the javax.transaction.TransactionManager to be made available it to it (which is server-specific in standard J2EE).
A PROPAGATION_REQUIRES_NEW scope always defines its own transaction synchronizations. Existing synchronizations will be suspended and resumed appropriately.
創建一個新事務。如果當前有事務就暫停它,然后創建一個新事務。
PROPAGATION_NOT_SUPPORTED
Do not support a current transaction; rather always execute non-transactionally. Analogous to the EJB transaction attribute of the same name.
NOTE: Actual transaction suspension will not work out-of-the-box on all transaction managers. This in particular applies to org.springframework.transaction.jta.JtaTransactionManager, which requires the javax.transaction.TransactionManager to be made available it to it (which is server-specific in standard J2EE).
Note that transaction synchronization is not available within a PROPAGATION_NOT_SUPPORTED scope. Existing synchronizations will be suspended and resumed appropriately.
不支持當前事務,而總是以非事務方式執行。
PROPAGATION_NEVER
Do not support a current transaction; throw an exception if a current transaction exists. Analogous to the EJB transaction attribute of the same name.
Note that transaction synchronization is not available within a PROPAGATION_NEVER scope.
不支持當前事務,如果當前有事務,就拋異常。
PROPAGATION_NESTED
Execute within a nested transaction if a current transaction exists, behave like PROPAGATION_REQUIRED else. There is no analogous feature in EJB.
NOTE: Actual creation of a nested transaction will only work on specific transaction managers. Out of the box, this only applies to the JDBC org.springframework.jdbc.datasource.DataSourceTransactionManager when working on a JDBC 3.0 driver. Some JTA providers might support nested transactions as well.
如果當前存在事務,就在一個嵌套的事務中執行。類似于PROPAGATION_REQUIRED。
轉載于:https://my.oschina.net/joeytai/blog/515099
總結
以上是生活随笔為你收集整理的Spring事务传播的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 9月全球浏览器份额之争:IE领先Chro
- 下一篇: 没有Hyper-V服务,WP Emula