Tuesday, December 4, 2012

JDBC Transaction Isolation Levels in java

Connection.setTransactionIsolation (level) 
JDBC Defined Constant
TRANSACTION_READ_UNCOMMITTED
Description: Allows dirty reads, non-repeatable reads, and phantom reads to occur. TRANSACTION_READ_COMMITTED
Description: Ensures only committed data can be read.
 TRANSACTION_REPEATABLE_READ
 Description:Is close to being "serializable," however, "phantom" reads are possible.
TRANSACTION_SERIALIZABLE
Description: Dirty reads, non-repeatable reads, and phantom reads are prevented. Serializable.

A "phantom" read occurs when one transaction reads all rows that satisfy a WHERE condition, and a second transaction inserts a row that satisfies that WHERE condition, the first transaction then rereads for the same condition, retrieving the additional "phantom" row in the second read.

Read Uncommitted 
The transaction can read uncommitted data (i.e., data changed by a different transaction that is still in progress). Dirty reads, nonrepeatable reads, and phantom reads can occur. Bean methods with this isolation level can read uncommitted changes.

Read Committed
The transaction cannot read uncommitted data; data that is being changed by a different transaction cannot be read. Dirty reads are prevented; nonrepeatable reads and phantom reads can occur. Bean methods with this isolation level cannot read uncommitted data.

Repeatable Read
The transaction cannot change data that is being read by a different transaction. Dirty reads and nonrepeatable reads are prevented; phantom reads can occur. Bean methods with this isolation level have the same restrictions as those in the Read Committed level and can execute only repeatable reads.

Serializable
The transaction has exclusive read and update privileges; different transactions can neither read nor write to the same data. Dirty reads, nonrepeatable reads, and phantom reads are prevented. This isolation level is the most restrictive.

No comments:

Post a Comment

Creating mirror of BST