【发布时间】:2015-03-02 17:06:13
【问题描述】:
- 如果我声明一个方法是非事务性的,那么我保存一条记录,做一些事情,保存另一条记录,即使第二次保存失败并抛出异常,第一次保存是否会提交,无论如何?李>
- 如果从另一个事务性服务方法调用 NonTransactional 服务方法,会发生什么?它现在是否成为外部事务的一部分,因此如果 SomeOtherdomainObject().save() 失败,第一个对象将被回滚?
例如
@Transactional
class SomeService {
@NotTransactional
def someMethod() {
new SomeDomainObject().save(failOnError:true, flush:true)
// do stuff, possibly throw a RuntimeException
new SomeOtherdomainObject().save(failOnError:true)
// do more stuff, possibly throw a RuntimeException
}
}
如此调用(在非事务调用情况下):
class SomeControler{
def someService
def someControllerMethod() {
someService.someMethod()
}
}
【问题讨论】:
-
由于您似乎有一个要测试的设置,我建议您将 Hibernate 日志记录设置为调试模式以查看会话和事务的工作情况。调试'org.hibernate'
标签: grails transactions commit