In my controller I have a action which updates 2 domain class.
I want it to make in such a way that if the second updates fails first update should roll back, basically if there is an error all the previous actions should roll back.
What's the basic idea here?
If you don't want to move your logic to a Service (possibly because you may be calling multiple services to execute both of those updates), annotate your controller action
with @Transactional
.
public MyController {
@Transactional
def save(){
myService.save(params)
myOtherService.save(params)
render "success"
}
...
}
Just move all your business logic to services that already are transactional. Use one service for first update action and second for another action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With