在我的申请中,我正在做以下
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
我认为我需要在第6行使用@Transaction(REQUIRED)。 这样只会回滚10条记录而不是所有记录都会回滚。
有人可以确认这是否是正确的方法?
答案 0 :(得分:0)
确保在公共方法上设置@Transactional
注释。参见
http://forum.spring.io/forum/spring-projects/data/49494-transactional-on-private-methods
和
Does Spring @Transactional attribute work on a private method?
如果updateRecords()是私有方法,则注释无法正常工作。