我正在使用带有 Java/Hibernate 的 oracle 数据库,表格如下:
Id| Status |....
1 PENDING
2 COMPLETED
从两个不同的事务中,执行以下查询:
1)select particular record, then update it
for(select some record from table){
update record status to COMPLETED
session.flush()
}
2) update records bunch
update table set status = 'PENDING' where....
(查询可以按任何顺序执行,因此 #1 可能出现在 #2 之前,反之亦然)
结果我有查询 2) 永远执行,所以我认为这是死锁情况。Oracle Enterprise Manager 显示查询 2) 等待 TX 锁定。
我该如何处理这种情况?
我阅读了有关select ... for update
构造(lockmode.upgrade
在 Hibernate 中)的信息,但在这种情况下,我认为它会锁定整个表,因此执行时间会增加。