O'Reilly logo

Spring Persistence with Hibernate by Ahmad Seddighi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Transactions in Hibernate applications

With JDBC, java.sql.Connection objects are always used to interact with the database, perform persistent operations, and manage transactions. With Hibernate, org.hibernate.Session objects are used to interact with the database. In turn, the Session objects use the Connection objects.

Each Session object uses an individual Connection object behind the scenes to perform persistent operations and manage transactions. The following snippet shows a typical procedure for transaction management with Hibernate:

Session session = HibernateHelper.getSession();
Transaction tx = null;
try {
tx = session.beginTransaction();

// Unit of work inside the transaction
tx.commit();
 tx = null; } catch (Exception e) { if (tx ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required