2021年4月2日星期五

Commit multiple tables at once in spring boot

I have below method which saves multiple tables. currently commit is happening separately for two tables. it means when i debug i can see commit happens seperatly for employeeDetails and companyDetails table

public void saveDB()  {     employeeDetailsRepo.save(employee);     companyDetailsRepo.save(companyDetails);    }  

What i am trying to do is commit should happens only once. e.g when i debug i don't want 1st table data committed and then next table. I want is once control coming out from this method we should se data saved in both the tables simultaneously. to do this I tried @Transcational on my saveDB method annotation along with @EnableTransactionManagement on main class of springBoot but it is not working. also tried below but not working

@Transactional(readOnly = false, rollbackFor = {              Exception.class }, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED)        public void saveDB()      {         employeeDetailsRepo.save(employee);         companyDetailsRepo.save(companyDetails);            }  

Also below property added in config flag

spring.datasource.hikari.auto-commit =false  
https://stackoverflow.com/questions/66906233/commit-multiple-tables-at-once-in-spring-boot April 01, 2021 at 10:19PM

没有评论:

发表评论