@Transactional 设置嵌套事务不回滚

@Transactional 设置嵌套事务不回滚

	@Transactional(rollbackFor = Exception.class)
    public void testA(RequestSchedulingVO requestSchedulingVO) {
    	...业务...
        BService.testB(param);
    }
	@Override
    @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, noRollbackFor = BusinessException.class)
//    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void testB(Long param) throws BusinessException {
        ...业务...
        try{
        }cach(Exception e){
        	throw new BusinessException(BaiduFaceErrorCode.FACE_CREATE_CONVERSATION_ERROR);
        }
    }

这里的事务要求是方法testB报错(BusinessException异常)时,testB事务不回滚,testA事务回滚.

方案一: testB设置事务为REQUIRES_NEW(创建一个新的事务,如果当前存在事务,则把当前事务挂起),并设置不回滚的异常类

方案二: testB设置事务为NOT_SUPPORTED(以非事务方式运行,如果当前存在事务,则把当前事务挂起)

参考文章:https://www.cnblogs.com/yepei/p/4716112.html

你可能感兴趣的:(java)