grails: playing with transaction on service (rolling back)


/ Published in: Groovy
Save to your folder(s)

how to rollback data on grails' service ....

for myutil --> please look at


Copy this code and paste it in your HTML
  1. class GtestService {
  2.  
  3. boolean transactional = true
  4.  
  5. // testing for transactional
  6. def x = new Gtest();
  7. x.testName = "tester";
  8. if(!x.save(flush:true)){
  9. throw new RuntimeException("cannot save x ");
  10. }else{
  11. println("x id : ${x.id}");
  12. def y = new Gtest();
  13. y.testName = "tester 2 - child";
  14. y.parentTest = x ;
  15. if(!y.save(flush:true)){
  16. throw new RuntimeException("cannot save y");
  17. }
  18.  
  19. // save !!!
  20. throw new RuntimeException("rollback both x and y");
  21. }
  22. }
  23. }

URL: www.wysmedia.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.