java - 如何在 Spring Boot 应用程序的事务类中显式提交?
问题描述
我在我的 Spring Boot 应用程序中的一个类上使用事务注释。在此类方法之一中,我们正在从远程位置下载内容并更新数据库。此下载正在循环运行。我只想在此方法中下载 50 次后明确提交。请建议。
解决方案
有两种方法可以实现这一目标..
要么在类中维护计数器局部变量状态,并在达到 50 时执行所需的操作。
尝试在该方法中打开两个事务并通过第一个事务更新数据库中的计数器,第二个事务将处理其余的事情。
Transaction transaction; transaction = session.beginTransaction(); ... (operations in the context of transaction) transaction.commit(); ... (other commands outside of any transaction) transaction = session.beginTransaction(); ... (and so on and so forth ....
推荐阅读
- c# - Temporary Index for a while loop
- wix - Wix 安装程序次要升级 exe 保持许可证不变
- python - 有没有办法将图像从散景 python 代码合并到独立的 HTML 中?
- python - 使用二维矩阵指定行和列的索引二维数组
- c++ - 如何在三元运算符中对齐冒号?
- flutter - 如何在 Flutter Better_player 上添加视频标题?
- javascript - 在浏览器中的 Tab 开关上暂停视频,但应在最小化浏览器窗口时继续播放
- python - 测试ndarray中子数组的存在
- c++ - 如何查找二维向量是否包含给定向量..?
- swift - SwiftUI列表无限滚动实现唯一的对象数组