Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

how does rollbackFor work ?

 
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?


 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • 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

 
ranger
Posts: 17346
11
Mac IntelliJ IDE 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
 
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
Posts: 17346
11
Mac IntelliJ IDE 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