我正在查看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個用戶試圖一次提交更改?
任何幫助,如何在編輯期間鎖定記錄,非常感謝!
謝謝!
完美的解釋,並有很大的聯繫!非常足智多謀,謝謝! –