• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Handling in Hibernate

 
Chandra Gupta
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello folks,

I have a basic question in Hibernate. Does Hibernate automatically rollback transactions if any exceptions occur during the transaction? If so, why do programmers usually catch exceptions and rollback explicitly? (Is it just for illustrating that thrown exceptions should be handled at some place in the application?)



Thanks,
Chandra
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is: it depends. See the section on transactions and concurrency in the Hibernate documentation. Also have a read through the transactions FAQ page. Both are worth reading.

To answer you question, if your code is running in a non-managed environment, you will need to handle transactions in some way or another. If your code is running in a managed environment you can leave it to the container.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic