SlideShare a Scribd company logo
Transaction and Concurrency Session - III
TRANSACTION – FAST BRUSH UP Atomicity  – refers to the ability that, either all of the tasks of a transaction are performed or none of them are. Consistency  - refers to the database being in a legal state when the transaction begins and when it ends. Isolation  - refers to the ability of the application to make operations in a transaction appear isolated from all other operations. Durability  - refers to the guarantee that once the user has been notified of success, the transaction will persist, and not be undone.
Programmatic Transaction Demarcation java.sql.Connection  – To be avoid in Hibernate application as it binds to plain JDBC environment. javax.transaction.UserTransaction  –  should be used in  Java EE application/JTA supported environment. org.hibernate.Transaction  – Unified transaction demarcation for Hibernate application; works both in managed and non-managed.
Transactions & Exceptions Hibernate 3.x exceptions are typed runtime exceptions. HibernateException – generic exception. JDBCException – thrown by hibernate internal JDBC layer. Subtypes – JDBCConnectionException SQLGrammarException LockAcquisitionException  DataException ConstraintViolationException
Hibernate typed exceptions 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.
Concurrency Strategies Hibernate never changes the Isolation level of connections obtained from Application server. Optimistic   Versioning – Numeric Version Field   Timestamp based   Without an additional field (not recommended) Pessimistic   Achieved with LockMode.UPGRADE or LockMode.UPGRADE_NOWAIT
Hibernate - LockMode LockMode.NONE  - Don’t go to the database unless the object isn’t in any cache. 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. 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.
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. LockMode.FORCE  - Force an increment of the objects version in the data-base, to indicate that it has been modified by the current transaction. Hibernate – Lock Mode (Cont..)

More Related Content

PDF
Struts Basics
PPTX
Struts introduction
PDF
Step by Step Guide for building a simple Struts Application
PDF
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
PDF
Frost - W3C Mobile Ajax Workshop 2007
PPT
Hibernate Session 1
PPT
08 Queries
Struts Basics
Struts introduction
Step by Step Guide for building a simple Struts Application
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
Frost - W3C Mobile Ajax Workshop 2007
Hibernate Session 1
08 Queries

Similar to Hibernate Session 3 (20)

PPT
05 Transactions
PDF
Hibernate concurrency
PPT
Svetlin Nakov - Database Transactions
PPTX
Чурюканов Вячеслав, “Code simple, but not simpler”
PPT
04 Data Access
PPT
Advanced Hibernate
DOCX
Hibernate3 q&a
PDF
Transactions and Concurrency Control Patterns
PPTX
Spring@transaction,isolation
PPTX
Transaction and concurrency pitfalls in Java
DOC
Hibernate tutorial for beginners
PDF
Transactions and Concurrency Control Patterns
PDF
Db locking
DOC
White Paper On ConCurrency For PCMS Application Architecture
PPT
2010 05-21, object-relational mapping using hibernate v2
PPT
04 dataaccess
PPT
Hibernate caching
PPTX
Transaction
PPTX
L12 Concurrent Programming
KEY
Appengine Nljug
05 Transactions
Hibernate concurrency
Svetlin Nakov - Database Transactions
Чурюканов Вячеслав, “Code simple, but not simpler”
04 Data Access
Advanced Hibernate
Hibernate3 q&a
Transactions and Concurrency Control Patterns
Spring@transaction,isolation
Transaction and concurrency pitfalls in Java
Hibernate tutorial for beginners
Transactions and Concurrency Control Patterns
Db locking
White Paper On ConCurrency For PCMS Application Architecture
2010 05-21, object-relational mapping using hibernate v2
04 dataaccess
Hibernate caching
Transaction
L12 Concurrent Programming
Appengine Nljug
Ad

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Cloud computing and distributed systems.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Network Security Unit 5.pdf for BCA BBA.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
The AUB Centre for AI in Media Proposal.docx
Cloud computing and distributed systems.
Chapter 3 Spatial Domain Image Processing.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Spectroscopy.pptx food analysis technology
sap open course for s4hana steps from ECC to s4
Assigned Numbers - 2025 - Bluetooth® Document
MIND Revenue Release Quarter 2 2025 Press Release
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Programs and apps: productivity, graphics, security and other tools
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Unlocking AI with Model Context Protocol (MCP)
Reach Out and Touch Someone: Haptics and Empathic Computing
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Ad

Hibernate Session 3

  • 2. TRANSACTION – FAST BRUSH UP Atomicity – refers to the ability that, either all of the tasks of a transaction are performed or none of them are. Consistency - refers to the database being in a legal state when the transaction begins and when it ends. Isolation - refers to the ability of the application to make operations in a transaction appear isolated from all other operations. Durability - refers to the guarantee that once the user has been notified of success, the transaction will persist, and not be undone.
  • 3. Programmatic Transaction Demarcation java.sql.Connection – To be avoid in Hibernate application as it binds to plain JDBC environment. javax.transaction.UserTransaction – should be used in Java EE application/JTA supported environment. org.hibernate.Transaction – Unified transaction demarcation for Hibernate application; works both in managed and non-managed.
  • 4. Transactions & Exceptions Hibernate 3.x exceptions are typed runtime exceptions. HibernateException – generic exception. JDBCException – thrown by hibernate internal JDBC layer. Subtypes – JDBCConnectionException SQLGrammarException LockAcquisitionException DataException ConstraintViolationException
  • 5. Hibernate typed exceptions 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.
  • 6. Concurrency Strategies Hibernate never changes the Isolation level of connections obtained from Application server. Optimistic Versioning – Numeric Version Field Timestamp based Without an additional field (not recommended) Pessimistic Achieved with LockMode.UPGRADE or LockMode.UPGRADE_NOWAIT
  • 7. Hibernate - LockMode LockMode.NONE - Don’t go to the database unless the object isn’t in any cache. 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. 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.
  • 8. 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. LockMode.FORCE - Force an increment of the objects version in the data-base, to indicate that it has been modified by the current transaction. Hibernate – Lock Mode (Cont..)