• Post Reply 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doing delete and create in same transaction so that rollback happens if any of them fail

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to do delete and create of a pojo from inside the component. First I do the delete and then call save to create it again. The problem is that when the save fails, the delete isn't getting rollbacked.


This is the controller from where the component is called.



From itemComponent.save, itemDeleteAndCreate is called like this

Item updatedItem = itemDeleteAndCreate(itemToUpdate, itemId, item);
I have enabled transaction in my config through EnableTransactionManagement. I have also tried mode as AdviceMode.ASPECTJ but even that isn't helping.

Also I have tried writing wrapper class and putting this function in there and then creating an object of that class and calling this function on that object.

The Builder class eventually call Dao of crudRepository which also has a transactional annotation on its delete and save function.

This function is called from controller which doesn't have @transactional on it.

Also I have tried propagation level of acquires new but even that didn't work.

I have also tried rollbackfor Exception.class but even that doesn't work.

Any help would be appreciated.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Arpan!

I really can't say, although transactioning is often not quite what you'd expect it to be when you're doing it through an abstract framework.

The bigger question to me is why you're doing a delete and re-create instead of simply updating the row in question. That's usually simpler and a lot more reliable. Among other things, you only have 1 database transaction to roll back, not 2.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Arpan,

What also needs to be seen is how the transaction has been configured. Can you also mention the transactionManager configuration.

regards,
Amit
 
reply
    Bookmark Topic Watch Topic
  • New Topic