This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
    Bookmark Topic Watch Topic
  • New Topic

how does rollbackFor work ?

 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hey guys,

I was going through the spring docs and came to know about this rollbackFor thing which's used to define the class for which the transaction must be rolled back in case exception occurs of that type. So tried the following-


But it does not work. It basically inserts the record and throws the runtime exception and does not rollback.

Am I right in assuming that that's the way it is supposed to work?


 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can you show your application context file ?
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks Christophe for the reply, here is the config file

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
By default transactions @Transactional will automatically rollback when any RuntimeException is thrown. So rollbackFor and noRollbackFor are used to customize specifically what exceptions you want to rollback for. So say you have 15 different RuntimeExceptions that might be thrown and you want only two of them to actually rollback your transaction, then you use the rollbackFor property to list just those two. If you want 12 to rollback and 3 not to rollback, then you use the noRollbackFor property. Basically they are the opposite of each other and you choose the one that will cause you the least amount of typing.

Mark
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks Mark for the nice explanation.

But here, in my case, why is it not roll backing the transaction?

Do I need to specify any subclass of RuntimeException for it to work ?

I see the records being inserted in the database even if the rollbackFor is defined here.

Best
 
pete reisinger
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Report post to moderator
as far as I know, your db needs to support transactions, so I can see that you are using mysql, is it innodb or myisam engine? only innodb supports transactions (I think)
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
Pete.

This is a thread from last August. Please try not to resurrect old threads.

Thanks

Mark
 
    Bookmark Topic Watch Topic
  • New Topic