nano7
nano7

Reputation: 2493

Transaction Management with Spring, Hibernate and mySQL, additional questions (using hibernate without transactions..)

Im working on developing a webapplication with Spring Framework 3.0.5 and Hibernate Framework 3.6 and Ive got some questions to it. I use Transaction Management with Annotations. (@Transactional) and my DAO is written on plain Hibernate 3 API.

1) How can I notice that a transaction is rolled back? (I mean, I do have to catch exceptions? or maybe check after, if everything worked? surrounding @transactional-methods with try-catch doesnt seem like a good thing to me)

2) Is it correct that transaction management with @transactional does not work (not rollback) when I catch the exception? (when I surround the call of a transactional-method with try-catch)

3) Is it possible to use Hibernate WITHOUT using transactions? so I could use Spring with Hibernate but without Transaction Management?

4) If its not possible to use Hibernate without using transactions, this means that my database management system always has to support transactional engines (like InnoDB). I cant use a myISAM table together with hibernate then? That would be a big disadvantage of hibernate then!?

thank you :-)

Upvotes: 0

Views: 1741

Answers (1)

JB Nizet
JB Nizet

Reputation: 691735

  1. Spring will automatically rollback a transaction if a runtime exception is thrown from a method annotated with @Transactional. You usually don't care if it's rolled back or not, because the exception will propagate up to the call stack. If you really need to know if the transaction is rolled back, use TransactionAspectSupport.currentTransactionStatus().isRollbackOnly().

  2. No. If you catch a runtime exception thrown from a transactional method, the transaction used to run this method is rolled back.

  3. No. You need transactions to use Hibernate, and this is a good thing. Doing database work without transactions is a recipe for disasters.

  4. Yes, you need a transactional engine.

Upvotes: 3

Related Questions