Spring transaction propagation and isolation levels

Source: Internet
Author: User
Tags serialization

7 levels of propagation for a transaction:

1)propagation_required: Supports the current transaction and creates a new one without a transaction.

2)Propagation_supports: Support the current transaction, if there is no transaction, handle it in a non-transactional manner

3)propagation_mandatory: Supports current transaction, throws exception without transaction

4)propagation_requires_new: New transaction, suspend current transaction if current transaction exists

5)propagation_not_supported: Operation is performed in a non-transactional manner and a transaction is suspended

6)Propagation_never: Handled in a non-transactional manner, with transactions pending

7)propagattion_nested: Executes within a nested transaction if a transaction is currently present. If there is currently no transaction, do something similar to propagation_required

4 Isolation levels of data:

READ UNCOMMITTED (unauthorized read, READ UNCOMMITTED):

If one transaction has already started writing data, the other transaction does not allow simultaneous writes, but allows other transactions to read the row data. This isolation level can be achieved through an "exclusive write lock".

Avoid updates being lost, but dirty reads may occur. That is, transaction B reads data that is not committed by transaction A.

Read Committed (authorized read, read commit):

Transactions that read data allow other transactions to continue to access the row's data, but uncommitted write transactions will prevent other transactions from accessing the row.

This isolation level avoids dirty reads, but may not be repeatable. Transaction a reads the data in advance, transaction B immediately updates the data, commits the transaction, and when transaction a reads the data again, the data has changed.

REPEATABLE READ (repeatable Read):

Transactions that read data prohibit write transactions (but allow read transactions), and write transactions prohibit any other transactions.

Non-repeatable reads and dirty reads are avoided, but Phantom reads can sometimes occur. This can be achieved through "shared read lock" and "exclusive write lock".


Serializable (serialization):

Provides strict transaction isolation. It requires the transaction to serialize execution, and the transaction can be executed one after the other, but not concurrently. If transaction serialization is not possible only through row-level locks, other mechanisms must be ensured that the newly inserted data is not accessed by the transaction that just performed the query operation.

Serialization is the highest transaction isolation level, at the expense of the highest cost, low performance, and is rarely used, at which time transactions are executed in order not only to avoid dirty reads, non-repeatable reads, but also to avoid Phantom reads.


The higher the isolation level, the greater the integrity and consistency of the data, but also the greater the impact on concurrency performance. For most applications, it is preferable to set the isolation level of the database system to read Committed. It avoids dirty reads and has better concurrency performance. Although it causes concurrency problems such as non-repeatable reads, Phantom reads, and second-class loss updates, the application can be controlled by pessimistic or optimistic locks on individual occasions where such problems may occur.

Spring transaction propagation and isolation levels

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.