Transaction isolation issues in Hibernate (dirty reads, non-repeated reads, Phantom reads), hibernate transactions

Source: Internet
Author: User

Transaction isolation issues in Hibernate (dirty reads, non-repeated reads, Phantom reads), hibernate transactions
Transaction isolation issues in Hibernate (dirty reads, non-repeated reads, Phantom reads)1. Features of transactions

Four features of transactions:

1) atomicity: transactions are the smallest unit for database operations.Operations that constitute transactions are inseparable

2) Consistency: All the operations that make up the transaction either succeed or fail. One of them failed and the transaction could not be completed

3) isolation: in concurrency, each transaction is independent.

4) Persistence: This is the result, indicating that the data will be permanently saved to the database after the transaction is committed.

2. transaction isolation

Three isolation issues of transactions:

1) Dirty read: one transaction reads data that has not been committed by another transaction.

For example, transaction A is reading a data, but the data has been read by transaction B, but transaction B has not yet committed. This causes transaction A to read the wrong data.

2) read-only: one transaction reads the data committed by another transaction.

For example, transaction A has two identical operations to read data a. After the first read operation on data a, transaction B modifies and submits data, when transaction A reads data a for the second time, two different results are obtained.

3) Phantom read: operation like an illusion

For example, when transaction A modifies all data in A table, transaction B inserts A new data into the table. After transaction A commits, you will find that another piece of data (that is, the new data of transaction B) has not been modified. This is like an illusion.

3. transaction isolation level

1) Serializable): Avoids dirty reads, non-repeated reads, and Phantom reads.

2) Repeatable read (Repeatable read): Avoids dirty reads and non-repeated reads.

3) Read committed (Read committed): Avoid dirty reading

4) Read uncommitted (Read uncommitted): Minimum level, which cannot be guaranteed in any situation

Related Article

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.