I have a service where to save a lot of data to db.
Using MYSQL
I have used like this
Domain1.withTransaction {text->
def domain1=//Create my domain object to save
if(!domain1.save()){
domain1.errors.each {
println it
}
throw new RuntimeException('unable to save domain1')
}
Domain2.withTransaction {text->
def domain2=//Create my domain object to save
if(!domain2.save()){
domain2.errors.each {
println it
}
throw new RuntimeException('unable to save domain2')
}
My problem if there occurred any problem in saving domain2 i need to roll back domain1 save also.
I need to remove domain1 from db.