JPA: locking when performing an indirect insertion

前端 未结 2 1737
梦谈多话
梦谈多话 2020-12-11 23:03

I am writing a piece of software that tracks medication usage. I am using JPA to interact with the database. My model consists of two entities: a Prescription a

2条回答
  •  醉话见心
    2020-12-11 23:26

    It Seems right.

    However, I'll suggest to test it first... the more simple way to do this, is through debugging ... using your preferred IDE, set a debug point after the sentence:

    entityMgr.lock(p, LockModeType.OPTIMISTIC_FORCE_INCREMENT);
    

    Later, try to invoke your addDose(prescriptionId) from two different clients, supplying the same prescriptionID ... and let one client finish first and see what happen with the another one.

提交回复
热议问题