Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Any best practice to dealwithjavax.persistence.OptimisticLockException?

Merge and persist do not issue SQL statements immediately, this only occurs when the context is synchronized with the database which occurs on Flush or commit. If you want to be able to catch the exception when it is a container managed transaction, you will have to call em.flush in a try/catch block.

Best Regards,
Chris

On Oct 20, 2017, at 10:54 AM, Andrei Ilitchev <andrei.ilitchev@xxxxxxxxxx> wrote:

May be OptimisticLockException is wrapped by javax.persistence.PersistenceException?

On 2017-10-20 10:32 AM, Yun Jie Zhou wrote:
Hello Andreas,
 
I was intent to try/catch the exception with the following code, but the control flow didn't reach the catch block.
Haven't figured out the reason.
 
public SvcDump updateSvcDump(final SvcDump svcDump)
  {
    SvcDump updated = null;
    try
    {
      updated = svcDumpDao.update(svcDump);
    }
    catch (final Exception e)
    {
      LOG.info("Cause: " + e.getCause());
      if (e.getCause() instanceof javax.persistence.OptimisticLockException)
      {
        // retry persist
        // first reload, and then copy
        final SvcDump reloaded = svcDumpDao.findBy(...)
        reloaded.setXXX(svcDump.getXXX());
        return svcDumpDao.update(reloaded);
      }
    }
    return updated;
  }
Thanks & Best Regards
 
 
----- Original message -----
From: Andreas Joseph Krogh <andreas@xxxxxxxxxx>
Sent by: eclipselink-users-bounces@xxxxxxxxxxx
To: eclipselink-users@xxxxxxxxxxx
Cc:
Subject: Re: [eclipselink-users] Any best practice to deal with javax.persistence.OptimisticLockException?
Date: Fri, Oct 20, 2017 7:12 PM
 
På fredag 20. oktober 2017 kl. 05:54:38, skrev Yun Jie Zhou <yunjiez@xxxxxxxxxx>:
Hello experts,
 
We got some OptimisticLockException in updating operations. Because it is Unchecked Exception, we cannot use try/catch with update operations. I searched the archived mail list, but didn't figure out a solution. Any best practice to add retry logic for concurrent access?
 
Best practice is try/catch. What's preventing you from catching OptimisticLockException?
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 
 



_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://urldefense.proofpoint.com/v2/url?u=https-3A__dev.eclipse.org_mailman_listinfo_eclipselink-2Dusers&d=DwICAg&c=RoP1YumCXCgaWHvlZYR8PQcxBKCX5YTpkKY057SbK10&r=GQtGouAnNB1NfXPRNVlsqjITIeGGPPcRPagQWKnQ6PM&m=jAy9gByyYIXhBjOLPuEXDzueyOhwQDJ8OiIN27TdwR4&s=YlMfEWIE1we190yMvmtc0IBD2a4PlX0ZswTB_i7Id-g&e= 

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://urldefense.proofpoint.com/v2/url?u=https-3A__dev.eclipse.org_mailman_listinfo_eclipselink-2Dusers&d=DwICAg&c=RoP1YumCXCgaWHvlZYR8PQcxBKCX5YTpkKY057SbK10&r=xVpSyIIO_uKj1KAOMnm4_-T4KVw7uqAp5EeFOtyE4gI&m=UfU55JUoOcp_QnxukS7X_y1Hcpc0kMCHqtvjdzjoMVE&s=4LAVwdMrEqEKp4QKBD_BFl4B0woCIzVDj4Ia2AwXr3M&e=


Back to the top