I did a web project by ussing SpringBoot.No matter how many times or how hard I try.It still doesn’t rollback.Is there anyone could help me.Thank you so much!
Here are the codes.
//a Controller
@PostMapping(value = "/savePlan")
public R saveYearPlan(@RequestBody ProductPlanOutputMain productPlanOutputMain){
return planService.saveOrUpdatePlanBatch(productPlanOutputMain);
}
@Service
public class PlanServiceImpl implements PlanService {
@Override
public R saveOrUpdatePlanBatch(ProductPlanOutputMain productPlanOutputMain) {
return saveOrUpdateDailyPlan(productPlanOutputMain);
}
@Transactional(rollbackFor = Exception.class)
public R saveOrUpdateDailyPlan(ProductPlanOutputMain productPlanOutputMain){
//Save data to DB.
productPlanOutputMainService.saveOrUpdatePlan(productPlanOutputMain);
//test rollback
threw new RuntimeException("something wrong");
}
}
I’ve tried many times.
>Solution :
@Transactional won’t work for a method called from the same class. Put it in a separate service class.