【问题标题】:java transaction shouldnot rollback all recordsjava事务不应该回滚所有记录
【发布时间】:2014-06-05 05:29:27
【问题描述】:

在我的应用程序中,我正在执行以下操作

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 条记录会回滚,而不是所有记录都会回滚。

谁能确认这是否是正确的方法?

【问题讨论】:

    标签: java sql database spring transactions


    【解决方案1】:

    确保在公共方法上设置了@Transactional 注释。见

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

    Does Spring @Transactional attribute work on a private method?

    如果 updateRecords() 是私有方法,则注释将不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-18
      • 2019-05-29
      • 2015-06-25
      • 1970-01-01
      • 2011-05-25
      • 1970-01-01
      相关资源
      最近更新 更多