【发布时间】:2012-06-01 15:46:45
【问题描述】:
我正在查看 EntityManager API,并试图了解我将执行记录锁定的顺序。基本上当用户决定编辑记录时,我的代码是:
entityManager.getTransaction().begin();
r = entityManager.find(Route.class, r.getPrimaryKey());
r.setRoute(txtRoute.getText());
entityManager.persist(r);
entityManager.getTransaction().commit();
根据我的反复试验,看来我需要在.begin() 之后设置WWEntityManager.entityManager.lock(r, LockModeType.PESSIMISTIC_READ);。
我自然认为我会在提交后使用WWEntityManager.entityManager.lock(r, LockModeType.NONE);,但它给了我这个:
Exception Description: No transaction is currently active
我还没有尝试将它放在提交之前,但这不会破坏锁定记录的目的,因为我的目标是避免在 50 个用户尝试一次提交更改的情况下冲突记录?
非常感谢任何关于如何在编辑期间锁定记录的帮助!
谢谢!
【问题讨论】:
标签: java locking entity entitymanager