如果应用程序 srv 隔离级别设置为 READ COMMITTED,会发生 OptimisticLockException 吗?
我正在使用带有“OpenJPA 1.2.3-SNAPSHOT”的 Websphere 应用程序服务器 7.0.0.0.9。 我已设置 jdbc 数据源 webSphereDefaultIsolationLevel=2 的属性(READ COMMITTED)。 我有这个问题,因为我的理解是,如果存在多个线程提交同一行的竞争,就会发生 OptimasticLockException。 但我认为如果隔离级别应用程序服务器设置为 READ COMMITTED,这种情况永远不会发生。
这是我遇到的异常..
<openjpa-1.2.3-SNAPSHOT-r422266:907835 fatal store error> org.apache.openjpa.persistence.OptimisticLockException: An optimistic lock violation was detected when flushing object instance
I am using Websphere application server 7.0.0.0.9 with ;OpenJPA 1.2.3-SNAPSHOT'.
I have Set property of jdbc data source webSphereDefaultIsolationLevel=2 (READ COMMITTED).
I have this question because My understanding is the OptimasticLockException occurs if there is race to commit the same row by multiple thread.
But I think this situation should never occur if isolation level app server is set to READ COMMITTED.
This is exception I am getting..
<openjpa-1.2.3-SNAPSHOT-r422266:907835 fatal store error> org.apache.openjpa.persistence.OptimisticLockException: An optimistic lock violation was detected when flushing object instance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,如果实体的
Version
属性在提交时比读取时更高(即已被另一个事务修改),则会引发OptimisticLockException
。下图说明了这一点(借自 JPA 2.0 并发和锁定):为什么?使用 READ COMMITTED 隔离级别时,不可重复读取可能会发生,但是:
e1
)总而言之,READ COMMITTED 不会阻止
OptimisticLockException
。Yes, an
OptimisticLockException
will be thrown if theVersion
attribute of an entity is higher (i.e. has been modified by another transaction) at commit time than when it was read. This is illustrated by the figure below (borrowed from JPA 2.0 Concurrency and locking):Why? When using a READ COMMITTED isolation level, non-repeatable reads may occur but:
e1
in the above example)To sum up, READ COMMITTED won't prevent
OptimisticLockException
.