/*** Support a current transaction, execute non-transactionally if none exists.* <p>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 will apply for.* As a consequence, the same resources (JDBC Connection, Hibernate Session, etc)* will be shared for the entire specified scope. Note that this depends on* the actual synchronization configuration of the transaction manager.*/
/*** Create a new transaction, suspending the current transaction if one exists.* <p><b>NOTE:</b> Actual transaction suspension will not work out-of-the-box* on all transaction managers. This in particular applies to* {@link org.springframework.transaction.jta.JtaTransactionManager},* which requires the {@code javax.transaction.TransactionManager} to be* made available it to it (which is server-specific in standard Java EE).* <p>A {@code 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.* <p><b>NOTE:</b> Actual transaction suspension will not work out-of-the-box* on all transaction managers. This in particular applies to* {@link org.springframework.transaction.jta.JtaTransactionManager},* which requires the {@code javax.transaction.TransactionManager} to be* made available it to it (which is server-specific in standard Java EE).* <p>Note that transaction synchronization is <i>not</i> available within a* {@code PROPAGATION_NOT_SUPPORTED} scope. Existing synchronizations* will be suspended and resumed appropriately.*/
Propagation.MANDATORY 必須當前存在事務,否則拋出異常
/*** Support a current transaction, throw an exception if none exists.* Analogous to EJB transaction attribute of the same name.*/
/*** Execute within a nested transaction if a current transaction exists,* behave like PROPAGATION_REQUIRED else. There is no analogous feature in EJB.* <p>Note: Actual creation of a nested transaction will only work on specific* transaction managers. Out of the box, this only applies to the JDBC*/
A constant indicating that dirty reads, non-repeatable reads and phantom reads* can occur. This level allows a row changed by one transaction to be read by* another transaction before any changes in that row have been committed* (a "dirty read"). If any of the changes are rolled back, the second* transaction will have retrieved an invalid row.
READ_COMMITTED 已提交讀
A constant indicating that dirty reads are prevented; non-repeatable reads* and phantom reads can occur. This level only prohibits a transaction* from reading a row with uncommitted changes in it.
REPEATABLE_READ 可重復讀
A constant indicating that dirty reads and non-repeatable reads are* prevented; phantom reads can occur. This level prohibits a transaction* from reading a row with uncommitted changes in it, and it also prohibits* the situation where one transaction reads a row, a second transaction* alters the row, and the first transaction rereads the row, getting* different values the second time (a "non-repeatable read").
SERIALIZABLE 串行化
A constant indicating that dirty reads, non-repeatable reads and phantom* reads are prevented. This level includes the prohibitions in* {@code ISOLATION_REPEATABLE_READ} and further prohibits the situation* where one transaction reads all rows that satisfy a {@code WHERE}* condition, a second transaction inserts a row that satisfies that* {@code WHERE} condition, and the first transaction rereads for the* same condition, retrieving the additional "phantom" row in the second read.
幻讀和不可重復讀相似容易混淆,幻讀指的是第一個事務相同查詢條件的查詢行數,另一個事務增加或刪除了某行(inserts a row),導致第一個事務兩次查詢的結果不同。不可重復讀指的是另一個事務修改( alters the row)了某行的數據。