首页新闻找找看学习计划

service中的事务处理异常不回滚

0
悬赏园豆:20 [已解决问题] 解决于 2017-04-11 18:38

我的使用的是spring annotation异常管理。然后我的service方法中使用了try。。。catch捕捉异常信息,catch块中throw出runtimeException,但是却不会异常回滚,这是为什么?

 

代码:

 

   @Transactional
    public Map alterAssessor(AssessorBo assessorBo){
        Map map=new HashMap();
       try{
           OperatorInfoDO operatorInfoDO=new OperatorInfoDO();
           OperatorRoleInfoDO operatorRoleInfoDO=new OperatorRoleInfoDO();
           AssessorInfoDO assessorInfoDO=new AssessorInfoDO();
           String nowTime=new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
           operatorInfoDO.setOperatorId(assessorBo.getOperatorId());
           operatorInfoDO.setUpdateTime(nowTime);
           operatorInfoDO.setLastUpdateOperator(assessorBo.getCurrentOperator().getOperatorId());
           operatorInfoDOMapper.updateByPrimaryKeySelective(operatorInfoDO);
           operatorRoleInfoDO.setOperatorId(assessorBo.getOperatorId());
           operatorRoleInfoDO.setRoleId(assessorBo.getRoleId());
           operatorRoleInfoDO.setUpdateTime(nowTime);
           OperatorRoleInfoDOExample example=new OperatorRoleInfoDOExample();
           example.createCriteria().andOperatorIdEqualTo(assessorBo.getOperatorId());
           operatorRoleInfoDOMapper.updateByExampleSelective(operatorRoleInfoDO,example);
           assessorInfoDO.setUsername(assessorBo.getUsername());
           assessorInfoDO.setAssName(assessorBo.getAssName());
           assessorInfoDO.setOperatorId(assessorBo.getOperatorId());
           assessorInfoDO.setFirstAssGroup(assessorBo.getFirstAssGroup());
           assessorInfoDO.setIsBlack(assessorBo.getIsBlack());
           assessorInfoDO.setIsRefuse(assessorBo.getIsRefuse());
           assessorInfoDO.setStatus(assessorBo.getStatus());
           assessorInfoDO.setMobile(assessorBo.getMobile());
           assessorInfoDOMapper.updateByPrimaryKeySelective(assessorInfoDO);
           map.put("statusCode","200");
       }catch(Exception e){
           logger.info("修改审核员信息失败",e);
           map.put("statusCode","300");
           map.put("message","修改审核员失败");
//           TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
           throw new RuntimeException("修改审核员信息失败",e);
       }finally{
           return map;
       }

    }
guodaxia的主页 guodaxia | 初学一级 | 园豆:87
提问于:2016-12-19 19:50
< >
分享
最佳答案
0

代码逻辑问题,自己调试

收获园豆:20
Yu | 专家六级 |园豆:12944 | 2016-12-20 09:16
其他回答(1)
0

是finally影响的,finally中return了map,一定会在方法后执行,也就是抛出异常后还要return这个对象,覆盖掉了前面的结果,所以没有捕捉到异常信息,不回滚!

guodaxia | 园豆:87 (初学一级) | 2017-04-11 18:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册