我想确认以下内容:
public void test() {
SomeEntity se = em.find(SomeEntity.class, 1);
// Do something...
se.setField = "test";
}
此处JPA将仅对se
执行乐观检查。
下一步:
public void test() {
SomeEntity se = em.find(SomeEntity.class, 1);
SomeOtherEntity soe = em.find(SomeOtherEntity.class, 1);
em.lock(soe, LockModeType.OPTIMISTIC);
// Do something...
se.setField = "test";
}
如果自上次读取后se
OR soe
已更改(数据库中的版本递增),JPA将抛出OptimisticException。
这是真的吗?
答案 0 :(得分:0)
em.flush()
的数据库时,OptimisticLockException 才会抛出 - 然后JPA Provider将比较版本字段并确定它已被另一个transactoin更改。