spring Two common transaction propagation Property Description

Transaction Transaction , the action is a set of operations on the database collection. A transaction is one of the core concepts of modern database theory.
If a group or all of the processing steps occur or step is not performed, we call the set of process steps as a transaction.
When all the steps are the same as operating a fully executed, we say that the transaction is committed.
Since part of the multi-step fails, resulting in no step is committed, the transaction must be rolled back to the original system state.

 

Seven commonly spread attributes:

1. PROPAGATION_REQUIRED - if there is a current transaction with the current transaction; if there is no current transaction, create a new one transaction. This is the most common choice.

2.PROPAGATION_SUPPORTS - support the current transaction, if no transaction is executed in a non-transactional way.

3.PROPAGATION_MANDATORY - support the current transaction, if no transaction, throw an exception.

4. PROPAGATION_REQUIRES_NEW - New Transaction, if the current transaction exists, the current transaction pending. Open a new transaction, the new transaction is finished, Wake pending before the transaction, proceed. If there is no current transaction, create a new transaction

5.PROPAGATION_NOT_SUPPORTED - perform operations to a non-transactional way, if the current transaction exists, put the current transaction pending.

6.PROPAGATION_NEVER - to perform non-transactional way, if the current transaction exists, an exception is thrown.

7.PROPAGATION_NESTED - if the current transaction exists, it is executed within nested transactions. If no transaction is carried out with PROPAGATION_REQUIRED similar operations.

 

 

Five isolation levels:
ISOLATION_DEFAULT
This is a PlatfromTransactionManager default isolation level, use the default database transaction isolation level.

Also with four corresponding JDBC isolation level;

ISOLATION_READ_UNCOMMITTED
This is the lowest transaction isolation level, which many outside do not charge a transaction can see the data that uncommitted transactions.
This isolation level will have dirty reads, non-repeatable reads and phantom reads.

ISOLATION_READ_COMMITTED
guarantee a transaction modifies the data submitted in order to be read by another transaction. Another transaction can not read the uncommitted transactions.
This transaction isolation level to avoid dirty read occurs, but may appear non-repeatable reads and phantom reads.

ISOLATION_REPEATABLE_READ
This transaction isolation level prevents dirty reads, non-repeatable reads. But the phantom read may occur.
In addition to ensuring that a transaction can not read data from another uncommitted transaction, but also to avoid the following situation to ensure the production (non-repeatable read).

ISOLATION_SERIALIZABLE
This is the most expensive, but the cost of the most reliable transaction isolation level. The transaction is processed as a sequential execution.
In addition to prevent dirty reads, non-repeatable read, but also avoids the phantom read.

Keywords:
1) Magic Reading: When Transaction 1 Transaction 2 reads the record increases recorded and submitted, you can see 2 new transaction record transaction 1 read again;
2) non-repeatable read: Transaction record reads 1 when the transaction 2 updates the records and submit, you can see the record after 2 revision 1 transaction when the transaction is read again;
3) dirty read: transaction 1 updates the record, but did not submit, transaction 2 reads the line after update and rollback transaction T1, T2 now read is invalid.

Dirty read: refers to a transaction reads a data uncommitted transactions

Non-repeatable read: reading a data table row within a transaction, a multiple read transaction reads a different result to the data submitted by another transaction.

Dummy read (Magic Reading): read the data inserted in another transaction a transaction, resulting in inconsistent read before and after (insert)

 

Two common property transaction propagation analysis:

1. Call the two service method in the Controller

If the propagation default, represents the default open Propagation.REQUIRED, all the same transaction, while the second service throws an exception, the transaction will be rolled back

 

 

2. The service still call two methods in the Controller

If a service in which method, in which the propagation properties of a service, to change REQUIRES_NEW, and the other service, without adding propagation properties, belongs to the default

This time if the transaction rollback occurs, the first service due to increased propagation properties,

 

https://blog.csdn.net/qianxiaopeng/article/details/82427689

https://blog.csdn.net/iteye_7592/article/details/81573981

https://blog.csdn.net/baidu_37107022/article/details/75578140

Guess you like

Origin www.cnblogs.com/qianjinyan/p/11348750.html