sinat_15523495
sinat_15523495
2015-03-23 07:50

关于spring注解事务传播机制的REQUIRED和REQUIRES_NEW

  • spring
  • 注解
  • 事务

这是有注解REQUIRED的方法:

 @Transactional(propagation=Propagation.REQUIRES_NEW)
 public void  updateUserRequired(int sid) {
        User user = new User();
        User user1 = null;
        user1=getUserInfo("1", null);
        user.setID("1");
        user.setNAME("w`````````````e");
        user.setPASSWORD("32141221");
        user1=getUserInfo("1", null);
        System.out.println(user1.getID()+" "+user1.getNAME()+" "+user1.getPASSWORD());
        updateUser(user);    
        user1=getUserInfo("1", null);
        System.out.println(user1.getID()+" "+user1.getNAME()+" "+user1.getPASSWORD());
            requiredService.updateTeaRequired_new();
       // throw new RuntimeException();
    }
这是有注解REQUIRES_NEW的方法:
    @Transactional(propagation=Propagation.REQUIRES_NEW)
    public void updateTeaRequired_new(){
        // TODO Auto-generated method stub
        userDao.updateTea(setTeacher());
        throw new RuntimeException();   
    }

如果REQUIRED的方法抛出runtime异常,REQUIRES_NEW不抛出异常,则REQUIRES_NEW提交,REQUIRED回滚。
但是反过来的话却是整体都回滚,这是为什么

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答