• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Transactions in Hibernate

 
Sudhanshu Mishra
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



 
L Foster
Ranch Hand
Posts: 185
10
Android Java Netbeans IDE
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic