首页 > 解决方案 > @Transactional 回滚后是否继续抛出catch异常

问题描述

@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {
    Exception.class,
    RuntimeException.class
})
public void parent() {
    try {
        child();
    } catch (RuntimeException re) {
        //i want do something at here, how to catch the child RuntimeException 
        //child Transactional cath RuntimeException,can i catch it here?
    }
}

@Transactional(propagation = Propagation.MANDATORY, rollbackFor = {
    Exception.class,
    RuntimeException.class
})
public void child() {
    try {
        xxxMapper.update();
    } catch (Exception e) {
        throw new RuntimeException("false");
    }
}

子事务捕获 RuntimeException 并回滚

我打电话给父母的孩子,我能抓住这个 RuntimeException 吗?

标签: java

解决方案


推荐阅读