Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring Transaction Management doesn't roll back my transaction

 
Duffman Be
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?

Thanks,
Duffman-
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic