我有一個服務,而把大量的數據保存到數據庫。 使用MySQL 我用這樣的Grails的回滾DB操作上的一些錯誤
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')
}
我的問題,如果沒有發生在節約域2我需要回滾域1也保存任何問題。
我需要從數據庫中刪除domain1。
不適合我。如果'domain2.save'導致RuntimeException,我可以在我的數據庫中看到domain1.save的效果。 – Jithin 2011-04-13 07:04:45
有沒有我需要爲此設置的任何配置? – Jithin 2011-04-13 09:19:16
你能驗證服務/ Grails的-應用程序/服務中?另外,依賴注入是聲明式事務處理的唯一方式。如果您使用新的運營商,如新SomeService() – 2011-04-13 14:08:46