【发布时间】:2014-04-08 04:47:12
【问题描述】:
可能是我误解了 Spring Requires_new 行为。这是我的代码:
@Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRED)
public void outterMethod() throws Exception{
innerMethod1();
innerMethod2();
}
@Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
public void innerMethod1() throws Exception{
testService.insert(new Testbo("test-2", new Date()));
}
@Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
public void innerMethod2() throws Exception{
testService.insert(new Testbo("test-2", new Date()));
throw new Exception();
}
当innnerMethod2 抛出异常时,我认为innerMethod1 仍然能够提交。但是所有外部和内部事务都会回滚。我在这里错了什么?当 innerMethod2 回滚时,我该如何提交 innerMethod1?
【问题讨论】:
标签: spring transactions behavior