wood burning stoves 2.0*
The moose likes Spring and the fly likes Spring Transaction Management doesn't roll back my transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring Transaction Management doesn Watch "Spring Transaction Management doesn New topic

Spring Transaction Management doesn't roll back my transaction

Duffman Be

Joined: Nov 14, 2009
Posts: 7

I'm implementing Spring Transaction Management into one of my webapplications, but it seems like it isn't working.
I have used this (http://static.springsource.org/spring/docs/2.0.4/reference/transaction.html) documentation to implement it.

I think this XML should make sure that a transaction should be rolled back whenever an exception occurs in one of my dao-classes.
However when I run this code:

When I run the "createPractice" method (which generates an error), it doesn't rollback the record I added in the first line of this method. Does anyone know what I'm doing wrong here?

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

Well, based on looking at your code, your DAO is catching all the exceptions instead of them being thrown. So in the end, there is no exception thrown.

Also by default all RuntimeExceptions thrown will cause a rollback, in most cases you won't need the "rollbackFor="Exception.class"

So in your DAO catch code, rethrow the exception up the stack.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
I agree. Here's the link: http://aspose.com/file-tools
subject: Spring Transaction Management doesn't roll back my transaction
Similar Threads
Spring and namespace-aware parser
jdbcTemplate, Transaction Rollback issue with "defaultAutoCommit" (Env - Tomcat, Spring, Sybase)
Spring Transaction using AOP in EJB Project
Jboss/JTA/spring "No JTA TransactionManager found"
JDBC Connection using spring declarative connection