mysql - grails rollback db operation on some error -



have service save lot of data db. using mysql have used this

domain1.withtransaction {text->             def domain1=//create domain object save               if(!domain1.save()){                domain1.errors.each {                       println                }                throw new runtimeexception('unable save domain1')         }         domain2.withtransaction {text->             def domain2=//create domain object save               if(!domain2.save()){                domain2.errors.each {                       println                }                throw new runtimeexception('unable save domain2')         } 

my problem if there occurred problem in saving domain2 need roll domain1 save also.
need remove domain1 db.

instead of using programatic transaction handling, service artifact allows automatic transaction handling. typically leads cleaner , more maintainable code.

you can use failonerror:true when save() force runtimeexception thrown.

example below:

class someservice {      static transactional = false      def servicemethod() {         def domain1=//create domain object save         def domain2=//create domain object save         domain1.save(failonerror:true)         domain2.save(failonerror:true)     } } 

update

i'm revisiting topic, after read response topic. grails integration test not rollback

please verify dialect setup innodb myisam tables aren't transactional. configured in config.groovy

datasource {       dialect= org.hibernate.dialect.mysqlinnodbdialect       ... } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -