@Override
@Transactional(rollbackFor = {Exception.class})
public PersonQualification saveBcAndPq(BaseCompany baseCompany, PersonQualification one) {
BaseCompany save = baseCompanyService.save(baseCompany);
if(save != null){
PersonQualification save1 = personQualificationRepository.save(one);
if(save1 != null){
return save1;
}else{
return null;
}
}
return null;
}
以上代码发生异常时,可以回退
@Override
@Transactional(rollbackFor = {Exception.class})
public PersonQualification saveBcAndPq(BaseCompany baseCompany, PersonQualification one) {
BaseCompany save = baseCompanyRepository.save(baseCompany);
if(save != null){
PersonQualification save1 = personQualificationRepository.save(one);
if(save1 != null){
return save1;
}else{
return null;
}
}
return null;
}
以上代码发生异常时,不能回退
快来和博主打成一片吧^_^
参考:Spring事务管理——回滚(rollback-for)控制_rollbackfor 非异常_JeangLee的博客-CSDN博客