在交易方法结束之前,在数据库中可以看到通过交易方法进行的更改
两个Spring Boot(Spring Data JPA)应用程序A1和APLICATION A2都读/写入名为T1的表。 t1 - > ID,DATA1,ISDEATER列
我的要求是A1将更新为true和conting的列。 然后,在相同的事务/方法中,随后A1将删除所有记录,这些记录是ISDEATER列更新为true的所有记录。 重要的是,在DB中反映了ISDEATED E列E的更新,因为A2在同一表中连续编写数据,以供已删除错误的记录。
到目前为止尝试的事情:
- 应用程序A1(无效。在Times _:
中引起PessimisticlockfailureException:
class ServiceLayer{
@Transactional
public void updateAndDeleteRecords(
helperServiceLayer.updateIsDeletedColumn(deletedRows);
repo.deleteAll(deletedRows);
}
}
class HelperServiceLayer{
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateIsDeletedColumn(List<TableRows> deletedRows) {
try{
repo.saveAll(deletedRows);
}
catch (Exception e){
e.printStackTrace();
}
}
}
使用Entity Manager手动提交更新delete column.didnt workwithin @transactional borgaries
使用TrasactionalTemplate,但遇到了问题
4。令我感到困惑的是,下面的简单代码
class ServiceLayer{
repo.saveAll(deletedRows);
repo.deleteAll(deletedRows);
}
我的理解是,除非A1末端的交易方法和更改是犯下的,否则更改对A2看不到。但是,我发现第4节中的上述代码在进行A1方法时没有拾取数据。 我需要了解我缺少的东西。 还是有一种干净的方法来做到这一点。
我无法更改设计。我所能做的就是将列更新为true,坚持下去,随后以相同的方法删除相同的行。 所有这些,而A2将尝试读取其ISDEATER值为false
编辑的数据:由于协和问题,系统的表现鲜明。这个问题的前提是错误的。由于记录的数量较少,解决方案4给出了它起作用的幻想。 采取了完全不同的方法来将一行标记为已删除而不是实际删除并基于此删除。谢谢Everone
Two Spring boot (spring data jpa) Application A1 and Aplication A2 both read/write to a table named T1.T1 -> ID, data1, isDeleted columns
My requirement is A1 will be updating column isDeleted to true and committing.
In the same transaction/method then subsequently A1 will delete all the records which as the isDeleted column updated to true.
It is important that the updation of isDeleted column e reflected in DB, because A2 is writing data continuously in the same table for the records which have isDeleted false.
Things tried so far:
- Application A1 (didnt work. Causes PessimisticLockFailureException at times_:
class ServiceLayer{
@Transactional
public void updateAndDeleteRecords(
helperServiceLayer.updateIsDeletedColumn(deletedRows);
repo.deleteAll(deletedRows);
}
}
class HelperServiceLayer{
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateIsDeletedColumn(List<TableRows> deletedRows) {
try{
repo.saveAll(deletedRows);
}
catch (Exception e){
e.printStackTrace();
}
}
}
Use entity manager to manually commit the update delete column.Didnt workwithin @transactional boundaries
Used TrasactionalTemplate but ran into issues
4. What baffles me is that a simple code below worked
class ServiceLayer{
repo.saveAll(deletedRows);
repo.deleteAll(deletedRows);
}
My understanding was unless the transactional method in A1 ends and the changes are committed, the changes will not be visible to A2. But what i found out that above code in section 4 works as A2 doesnt pick up data while A1 method is in progress.
I need to understand what I am missing.
Or is there a clean way of doing this.
I cannot change the design. All i can do is update the column isDeleted to true, persist it, subsequently delete the same rows in the same method.
All this while A2 will be trying to read data whose isDeleted value is false
EDIT: the system was behaving wierdly because of concurret issues. The premise of this question was wrong. Because of less number of records solution 4 gave the illusion that it worked.
Took a completely different approach of marking a row as deleted instead of actually deleting it and filter based on that. Thanks everone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论