grails回滚db操作时出现某些错误
|
我有一项将大量数据保存到db的服务。
使用MYSQL
我已经习惯了
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\')
}
我的问题,如果在保存domain2时发生任何问题,我还需要回滚domain1保存。
我需要从数据库中删除domain1。
没有找到相关结果
已邀请:
4 个回复
姬第柔炒
更新 在阅读了对另一个主题的回复之后,我正在重新讨论这个主题。 Grails集成测试不会回滚 请确认您的方言已设置为InnoDB,因为MyISAM表不是可事务的。这是在您的
中配置的
盛虱
校勒魏寡
闭包放入
闭包中,因此Domain2事务中的错误将回滚Domain1和Domain2事务 像这样
购藏盗码韦