回滚带批注@Transactional方法
2022-09-03 05:39:50
日安。下面的代码:
class A{
private B b;
@Transactional
public SomeResult doSomething(){
SomeResult res = null;
try {
// do something
} catch (Exception e) {
res = b.saveResult();
}
return res ;
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
class B{
public SomeResult saveResult(){
// save in db
}
}
据我所知,如果方法中存在异常,则不会回滚事务。如何让它滚动?并返回了一些结果doSomething