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?

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=jf_iaSHvJObTbx-siA1ZOg&r=VNNgiyVygNGEoRSscxs2M1H3AcrcHHU6MCCeO1XQcXM&m=l-red0exCfKIVv6vJw3sjCtqTziIGCHrrgWxwxuyV24&s=dlAThL8eQjy4k8hF78J715U_yLWf2cBz7wKgNxOGYEE&e=
 


Back to the top