Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why the @Transactional doesn't work in a web project which is based on SpringBoot?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

@Transactional won’t work for a method called from the same class. Put it in a separate service class.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading