【发布时间】:2014-01-08 03:00:22
【问题描述】:
在我的应用程序中,我正在执行以下操作
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 条记录会回滚,而不是所有记录都会回滚。
谁能确认这是否是正确的方法?
【问题讨论】:
-
您使用什么框架/工具来更新您的表格?
-
我在叫一个道班。每当出现故障时,该 dao 类都会返回(抛出)异常。我不知道 dao 实现了什么框架。
标签: java sql database spring transactions