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