Tuesday, December 31, 2013

hibernate configure transaction Isolation Level

In the hibernate config file you can configure the default jdbc-transaction level. Hibernate uses the codes of the java.sql.Connection  class, which are listed above.
  •   public static final int TRANSACTION_NONE = 0;
  •   public static final int TRANSACTION_READ_UNCOMMITTED = 1;
  •   public static final int TRANSACTION_READ_COMMITTED = 2;
  •   public static final int TRANSACTION_REPEATABLE_READ = 4;
  •   public static final int TRANSACTION_SERIALIZABLE = 8;
To use Repeatable Read transactions you just have to type the number 4 in your isolation property.
4
Here a short list, what each level means:
  • TRANSACTION_READ_UNCOMMITTED -> Allows dirty reads, non-repeatable reads, and phantom reads to occur.
  • TRANSACTION_READ_COMMITTED -> Ensures only committed data can be read.
  • TRANSACTION_REPEATABLE_READ -> Is close to being “serializable,” however, “phantom” reads are possible.
  • TRANSACTION_SERIALIZABLE -> Dirty reads, non-repeatable reads, and phantom reads are prevented. Serializable.
Performance of the software decreased by a higher transaction level. So you should check if you need more stability or performance. Depends always by the software you build up.

No comments: