spring-data - 使用 pessimistic_write 锁查找和更新不能防止乐观锁失败?
问题描述
我尝试使用 pessimistic_write 锁来查找和更新一条记录,如下所示,
transactionService.executeTransaction(() -> {
Entity newEntity = em.find(entityClass, id, LockModeType.PESSIMISTIC_WRITE);
newEntity = setEntityWithProperty.setEntity(newEntity, property);
});
我在 Spring 中使用 transactionTemplate。实体本身有一个版本字段来使用乐观锁。使用 pessimistic_write 锁,在事务期间(查找然后更新),其他线程应该无法读取或写入记录,对吧?但是当提交事务时,我仍然可以得到 OptimisticLockFailuerException。为什么会发生这种情况?
解决方案
推荐阅读
- scala - Kafka consumer not returning any events
- python-3.x - 使用 pythonanywhere 在 Web 上部署 Python Flask 应用程序
- ios - UItableViewCell 更新错误的单元格标签文本
- c# - 连接到 MS Access
- javascript - 无法让 javascript 在 jsfiddle 中以 HTML 形式工作
- javascript - 如何使用 moment.js 和 ES6 创建小时 + 分钟数组?
- python - 运行 python opencv 脚本时出现“选择超时”错误
- java - Object.toString() OutOfMemory - 如果它包含 Base64,如何拆分?
- html - 带有 typescript 和 html 的动态表
- couchbase - 计数查询在 Couchbase 中运行速度太慢