@Transactional事物不回滚

来自ling
跳转至: 导航搜索

默认下不添加@Transactional,程序只能查询,以下操作不回写入数据库,添加@Transactional后可以写入数据库,但不能回滚.需要添加回滚条件rollbackOn=Throwable.class

@Transactional
    public void registerCompanyAndUser(@RequestBody Map<String, Map> companyAndUser) throws Exception {
        Map<String, Object> company = (Map<String, Object>) companyAndUser.get("company");
        Map<String, Object> user = (Map<String, Object>) companyAndUser.get("user");
        this.companyService.registerCompany((String) company.get("id"), (String) company.get("name"), (String) company.get("desc"));
        if(true){
            throw new Exception("1");
        }
        this.userService.registerAdministrator((String) user.get("username"), (String) user.get("cname"), (String) user.get("ename"), (String) user.get("password"), (String) user.get("email"), (String) user.get("mobile"), (String) company.get("id"));
    }

-->

@Transactional-->@Transactional(rollbackOn=Throwable.class)