【发布时间】:2018-10-25 08:56:48
【问题描述】:
似乎当一个具有 NESTED 传播的事务性 spring 方法调用另一个具有传播 REQUIRED 的事务性方法时,内部事务可以强制回滚外部逻辑事务。谁能确认一下?
我想处理 RuntimeException 而不是回滚外部事务,例如:
@Transactional
class A {
@Autowired
B b;
@Autowired
C c;
void methodA() { // outer transaction, this should not be rollback but currently getting UnexpectedRollbackException
b.methodB(() -> c.methodC());
}
}
@Transactional(propagation = Propagation.NESTED)
class B {
void methodB(Runnable action) { // inner nested transaction
try{
action.run();
} catch (Exception e){
// nothing
}
}
}
@Transactional
class C {
void methodC() { // inner required transaction
throw new RuntimeException();
}
}
【问题讨论】:
-
在看起来应该做的地方显示代码。
-
我添加了示例代码