Reputation: 3915
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?
Upvotes: 4
Views: 4183
Reputation: 4809
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"
}
...
}
Upvotes: 10
Reputation: 1266
Just move all your business logic to services that already are transactional. Use one service for first update action and second for another action.
Upvotes: 7