Spring's 4 transactional features, 5 isolation levels, 7 propagation behaviors

Source: Internet
Author: User

Go to the interview, the interviewer asks, say something about the isolation levels of spring transactions, and which of your projects is used. A blank face, then ...

Spring transaction:

What is a transaction:
A set of operations on a transactional logic that makes up each logical unit of this set of operations, either successfully together or with failure.

Transaction characteristics (4 types):  
atomicity (atomicity): Emphasizing the indivisibility of transactions.  
Consistency (consistency): the integrity of the data before and after the execution of a transaction is consistent.  
Isolation (isolation): In the course of a transaction execution, you should not be disturbed by other transactions  
persistence (durability): Once a transaction is finished, the data is persisted to the database


Span style= "Font-family:arial, Helvetica, Sans-serif; FONT-SIZE:16PX "> Dirty read: One transaction READ UNCOMMITTED data   of another transaction;
non-repeatable READ: One transaction reads the data of an update that has been committed by another transaction, causing inconsistent results for multiple queries.  
Unreal read: One transaction reads the insert data that has been committed by another transaction, causing inconsistencies in the results of multiple queries.

Troubleshoot read problems: Set the Transaction Isolation Level (5)  
default This is a Platfromtransactionmanager default isolation level that uses the default transaction isolation level of the database.  
uncommitted read (read uncommited): Dirty read, non-repeatable read, virtual read all may occur  

repeatable READ (Repeatable Read): Avoid dirty reads and non-repeatable reads. But it could happen.  
serialization (serializable): Avoid all of the above reading problems.  
mysql default: Repeatable read  
oracle default: Read Committed

Read uncommited: Is the lowest transaction isolation level, which allows another transaction to see uncommitted data for this transaction.
Read commited: Ensure that one thing is committed before it can be read by another transaction. Another transaction cannot read data that is not committed by the object.
REPEATABLE READ: This level of transaction isolation prevents dirty reads and cannot be read repeatedly. But phantom reads may occur. In addition to ensuring that one transaction cannot read uncommitted data from another transaction, the following conditions are avoided (non-repeatable read).
Serializable: This is the most cost-effective, but most reliable, transaction isolation level. Transactions are processed for sequential execution. In addition to preventing dirty reads and non-repeatable reads, Phantom reads are avoided (avoid three types).

The propagation behavior of a transaction
propagion_xxx: The propagation behavior of a transaction
* Ensure the same transaction
Propagation_required supports the current transaction and creates a new one if it does not exist (default)
Propagation_supports supports the current transaction and does not use a transaction if it does not exist
Propagation_mandatory supports the current transaction and throws an exception if it does not exist
* Guaranteed not to be in the same transaction
Propagation_requires_new If a transaction exists, suspends the current transaction, creates a new transaction
propagation_not_supported runs in a non-transactional manner, suspending the current transaction if a transaction exists
Propagation_never runs in a non-transactional manner, throws an exception if a transaction exists
propagation_nested If the current transaction exists, the nested transaction executes

Spring's 4 transactional features, 5 isolation levels, 7 propagation behaviors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.