java事务不应回滚所有记录
在我的应用程序中,我将执行以下操作java事务不应回滚所有记录,java,sql,database,spring,transactions,Java,Sql,Database,Spring,Transactions,在我的应用程序中,我将执行以下操作 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 an
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条记录将回滚,而不是所有记录都将回滚
有人能确认这是否是正确的方法吗?确保在公共方法上设置了
@Transactional
注释。看
及
如果updateRecords()是私有方法,则注释将不起作用