我是spring / grails交易的新手,我在阅读后仍然不清楚所以我在这里发帖,
我有一个注释为@Transactional的服务类 我有一些方法注释为
@Transactional(propagation = Propagation.REQUIRES_NEW)
其中一些不是。
@Transactional
class SomeService {
def findJob() {
MyInstance myInstance = getMeAJob();
if (myInstance) {
doSomeThing(myInstance)
doTask()
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception)
private doSomeThing(MyInstance myInst) {
myObj = MyInstance.lock(myInst.id)
try {
differentObj = doTask(myObj)
myObj.save()
doAnotherThing()
}
} catch (Exception e) {
log("Error in doAnotherTask")
}
}
private doAnotherThing(MyInstace myInst) {
perform some update on myInst
myInstant.save(flush: true)
}
private doTask() {
}
将在t2执行的方法 - doSomeThing() - 不会影响 异常情况下的“t1”(回滚)
doAnotherThing()方法将使用哪一个?因为我是从doSomething()调用它的?