1

In my application, I am doing the following

1. Getting 25 records from the DB.
2. Update every 10 records
   Here I have a loop to update every 10 records.so there will be 3 loops.
   For each loop I need to have a new transaction.(so that only  the 10 record will rollback and not all the records will rollback)   
//line 1  
    getRecords();//25 records from DB  //line 2  
    For(Records r: loop) {  //line 3  
    add 10 records;  //line 4  
    call update method(object with 10 records)   //line 5  
}
  //line 6  
updateRecords()//this method updates the 10 records\\line 7  

Here I think I need to use @Transaction(REQUIRED) at line 6. so that only the 10 records will rollback and not all the records will rollback.

Can anyone please confirm if this is the correct approach?

1 Answers1

0

Be sure the @Transactional annotation is set on public method. See

http://forum.spring.io/forum/spring-projects/data/49494-transactional-on-private-methods

and

Does Spring @Transactional attribute work on a private method?

If the updateRecords() is private method the annotation won't work.

Community
  • 1
  • 1
StanislavL
  • 56,971
  • 9
  • 68
  • 98