Transaction and Concurrency Session - III
TRANSACTION – FAST BRUSH UP <ul><li>Atomicity  – refers to the ability that, either all of the tasks of a transaction are ...
Programmatic Transaction Demarcation <ul><li>java.sql.Connection  – To be avoid in Hibernate application as it binds to pl...
Transactions & Exceptions <ul><li>Hibernate 3.x exceptions are typed runtime exceptions. </li></ul><ul><li>HibernateExcept...
Hibernate typed exceptions <ul><li>All exceptions throws by Hibernate are RuntimeException and are fatal exceptions. It is...
Concurrency Strategies <ul><li>Hibernate never changes the Isolation level of connections obtained from Application server...
Hibernate - LockMode <ul><li>LockMode.NONE  - Don’t go to the database unless the object isn’t in any cache. </li></ul><ul...
<ul><li>LockMode.UPDGRADE_NOWAIT - The same as UPGRADE, but use a SELECT ...  FOR UPDATE NOWAIT, if supported. This disabl...
Upcoming SlideShare
Loading in …5
×

Hibernate Session 3

1,467 views
1,396 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,467
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
48
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Hibernate Session 3

  1. 1. Transaction and Concurrency Session - III
  2. 2. TRANSACTION – FAST BRUSH UP <ul><li>Atomicity – refers to the ability that, either all of the tasks of a transaction are performed or none of them are. </li></ul><ul><li>Consistency - refers to the database being in a legal state when the transaction begins and when it ends. </li></ul><ul><li>Isolation - refers to the ability of the application to make operations in a transaction appear isolated from all other operations. </li></ul><ul><li>Durability - refers to the guarantee that once the user has been notified of success, the transaction will persist, and not be undone. </li></ul>
  3. 3. Programmatic Transaction Demarcation <ul><li>java.sql.Connection – To be avoid in Hibernate application as it binds to plain JDBC environment. </li></ul><ul><li>javax.transaction.UserTransaction – should be used in Java EE application/JTA supported environment. </li></ul><ul><li>org.hibernate.Transaction – Unified transaction demarcation for Hibernate application; works both in managed and non-managed. </li></ul>
  4. 4. Transactions & Exceptions <ul><li>Hibernate 3.x exceptions are typed runtime exceptions. </li></ul><ul><li>HibernateException – generic exception. </li></ul><ul><li>JDBCException – thrown by hibernate internal JDBC layer. Subtypes – </li></ul><ul><ul><ul><ul><ul><li>JDBCConnectionException </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>SQLGrammarException </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>LockAcquisitionException </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>DataException </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>ConstraintViolationException </li></ul></ul></ul></ul></ul>
  5. 5. Hibernate typed exceptions <ul><li>All exceptions throws by Hibernate are RuntimeException and are fatal exceptions. It is the programmers responsibility in non-managed environment to rollback the transaction in case of exceptions. </li></ul>
  6. 6. Concurrency Strategies <ul><li>Hibernate never changes the Isolation level of connections obtained from Application server. </li></ul><ul><li>Optimistic </li></ul><ul><li> Versioning – Numeric Version Field </li></ul><ul><li> Timestamp based </li></ul><ul><li> Without an additional field (not recommended) </li></ul><ul><li>Pessimistic </li></ul><ul><li> Achieved with LockMode.UPGRADE or LockMode.UPGRADE_NOWAIT </li></ul>
  7. 7. Hibernate - LockMode <ul><li>LockMode.NONE - Don’t go to the database unless the object isn’t in any cache. </li></ul><ul><li>LockMode.READ - Bypass all caches, and perform a version check (if applicable) to verify that the object in memory is the same version that currently exists in the database. </li></ul><ul><li>LockMode.UPDGRADE - Bypass all caches, do a version check (if applicable), and obtain a database-level pessimistic upgrade lock, if that is supported. Equivalent to LockModeType.READ in Java Persistence. This mode transparently falls back to LockMode.READ if the database SQL dialect doesn’t support a SELECT ... FOR UPDATE option. </li></ul>
  8. 8. <ul><li>LockMode.UPDGRADE_NOWAIT - The same as UPGRADE, but use a SELECT ... FOR UPDATE NOWAIT, if supported. This disables waiting for concurrent lock releases, thus throwing a locking exception immediately if the lock can’t be obtained. </li></ul><ul><li>LockMode.FORCE - Force an increment of the objects version in the data-base, to indicate that it has been modified by the current transaction. </li></ul>Hibernate – Lock Mode (Cont..)

×