Transaction Isolation Level
- determines how locks are set, which can range from not supporting transactions at all to supporting transactions that enforce very strict access rules
Transaction - Read Anomalies
- A dirty read occurs when accessing an updated value that has not been committed because it is possible for that value to be rolled back to its previous value. If you read a value that is later rolled back, you will have read an invalid value
- A non-repeatable read occurs when transaction A retrieves a row, transaction B subsequently updates the row, and transaction A later retrieves the same row again. Transaction A retrieves the same row twice but sees different data.
- A phantom read occurs when transaction A retrieves a set of rows satisfying a given condition, transaction B subsequently inserts or updates a row such that the row now meets the condition in transaction A, and transaction A later repeats the conditional retrieval. Transaction A now sees an additional row. This row is referred to as a phantom
- A serialization anomaly The result of successfully committing a group of transactions is inconsistent with all possible orderings of running those transactions one at a time
Transaction - Isolation Levels ()
The interface java.sql.Connection includes five values that represent the transaction isolation levels you can use in JDBC:
|
Isolation Level |
Dirty Reads |
Non-Repeatable Reads |
Phantom Reads |
Serialization Anomaly |
Description |
|---|---|---|---|---|---|
|
|
NA |
NA |
NA |
NA |
no transaction (i.e. any queries executed within a “transaction” are immediately committed to the database) no rollback is possible |
|
|
Allowed |
Allowed |
Allowed |
Allowed |
any outside queries executed AFTER the start of a transaction are visible within the transaction (both uncommitted and committed queries) |
|
|
Prevented |
Allowed |
Allowed |
Allowed |
any outside queries executed AFTER the start of a transaction are visible within the transaction (just committed queries) |
|
|
Prevented |
Prevented |
Allowed |
Allowed |
any outside queries executed AFTER the start of a transaction are NOT visible within the transaction |
|
|
Prevented |
Prevented |
Prevented |
Prevented |
transactions are serialized |