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?

But why cannot be caught by generic Exception? Any potential reasons? thanks.
 
Thanks & Best Regards

Austin ( 周运杰/Yun Jie Zhou)
 
 
----- Original message -----
From: Andrei Ilitchev <andrei.ilitchev@xxxxxxxxxx>
Sent by: eclipselink-users-bounces@xxxxxxxxxxx
To: eclipselink-users@xxxxxxxxxxx
Cc:
Subject: Re: [eclipselink-users] Any best practice to dealwithjavax.persistence.OptimisticLockException?
Date: Fri, Oct 20, 2017 10:55 PM
 

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=jf_iaSHvJObTbx-siA1ZOg&r=VNNgiyVygNGEoRSscxs2M1H3AcrcHHU6MCCeO1XQcXM&m=Dsp3TJlc5DpnqwEbUgk7BVj8X1VUTbWiYVIvZxFmobc&s=tsquspO9OJbaNGg9J6t01WlD4oC7uPZ-Xk8TexnDi6Y&e=
 


Back to the top