Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JDBC Transactions in Hibernate

 
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers

I am aware that Hibernate uses JDBC API for persistece.
However, I have one query regarding JDBC transactions in Hibernate. I am posting the below snippet and have written what I understand from each line of code:



Could you please verify and correct my understanding, before I study further?

Thanks



 
Ranch Hand
Posts: 259
15
Android Angular Framework Spring AngularJS Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks accurate, to my understanding. The overall pattern is:
* get a transaction (from somewhere--here you are using the session, but sometimes you can get that other ways).
* do your processing. If all goes well, commit the transaction (make all the stuff actually happen).
* if all does NOT go well, you can have that exception. I don't see a comment, but I bet you already know this part.

In the event of failure, you can rollback the transaction. That makes all the database changes you had setup during the processing, go away. That means, had you added five rows to 3 different tables, and then there was some kind of key constraint problem, your exception would have happened, and all the tables would be restored to the previously (presumably healthy) state.

And you probably knew this was all about the "C" in ACID--Consistency. No half-complete database changes.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!