How to handle OptimisticLockException in JPA
<p>I have OptimisticLockException that as follow this code(Error Code:entity = em.merge(entity);) because of that when user click save button at same time twice from diffrenet browser tab.
<strong>Note:entity.getOid() is not null!</strong>
who can help me...</p>

<pre><code>public static synchronized KirKiraciSozlesmeYeniKayitForm kaydet(KirKiraciSozlesmeYeniKayitForm form, EntityManager em) {

    KirKiraciSozlesme entity = new KirKiraciSozlesme();
    UtilInsCore.copyProperties(form, entity);

    if (entity.getOid() == null) {
        Long oid = DBUtil.getSeqNextValue(em, "KIR_KIRACI_SOZLESME_SEQ");
        entity.setOid(oid);
    } 
    entity = em.merge(entity);
    em.flush();
    UtilInsCore.copyProperties(entity, form);

    return form;
}
</code></pre>

<p>Thank you in advance.</p>