Coping with the exception of optimistic locking in OpenJPA...?

Hi all

I have the code example that I'm calling from the main class (I don't use any server/container)
   public void updatePortName(String oldPortName, String newPortName)
                {
          EntityTransaction trx = em.getTransaction();
          trx.begin();// Checkpoint
          BcsPrimaryBuffer bcsPrimaryBuffer = (BcsPrimaryBuffer) em.find(BcsPrimaryBuffer.class,  
                                                                                                                                           oldPortName);
          
                                bcsPrimaryBuffer.setPort(newPortName); // IS THIS CORRECT ???
          em.merge(bcsPrimBuffer);

                                trx.commit();  //Throws exception
     }
  
I get the following exception on trx.commit ()...
My question is that I take the right approach here... ?
I need to update the port value in the BcsPrimaryBuffer table in db to the new value.

If need more info please let me know.

Exception in thread "main" <openjpa-1.0.0-r420667:568756 fatal store error> org.apache.openjpa.persistence.RollbackException: Optimistic locking errors were detected when flushing to the data store.  The following objects may have been concurrently modified in another transaction: [org.apache.openjpa.enhance.entities$BcsPrimaryBuffer$pcsubclass-JCVLFLU0523HD2160033-1-1-2-1]
     at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:419)
     at entities.BcsPrimaryBufferDAO.updatePortName(BcsPrimaryBufferDAO.java:194)
     at com.test.local.EntityManagerTester.main(EntityManagerTester.java:36)
Caused by: <openjpa-1.0.0-r420667:568756 nonfatal store error> org.apache.openjpa.persistence.OptimisticLockException: Optimistic locking errors were detected when flushing to the data store.  The following objects may have been concurrently modified in another transaction: [org.apache.openjpa.enhance.entities$BcsPrimaryBuffer$pcsubclass-JCVLFLU0523HD2160033-1-1-2-1]
     at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2096)
     at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1946)
     at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1844)
     at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1762)
     at org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
     at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1292)
     at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:861)
     at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:408)
     ... 2 more

Ok
so your idea of "delete the entity with the old port number, insert a new one with the new port number" would be a good solution

Tags: Java

Similar Questions

Maybe you are looking for

  • HP 15-d035dx W8.1 of W7 Downgrade - Driver install failures (System requirements has not met)

    Users/HP, Hello fellow forum members I just bought a new laptop from HP 15-d035dx like a beam from BestBuy. Preinstalled with OS Windows8.1 (my first time using it) and I immediately rejected and decided to install my copy of Windows 7 Pro. I took al

  • COM PORT is missing in Device Manager

    When I have found that on that day there, I opened Device Manager, devices mobile COM port option has disappeared from the Device Manager. This who should I do to solve this problem...

  • Each program has shunk

    Each program has shunk expands on my 17 "display Desktop. nothing no longer uses the ability of screen size? I tried adjusting the size of resolution and display text - no help.

  • Guard remote office Session disconnect

    Hi, I've set up a Windows Server 2012 R2 as a Hyper-V host computer for my virtual machines. Access to remote desktop session host, but the session keeps disconnecting after a few minutes. My server has the following roles at present: Any suggestions

  • On the user process start/exit Windows memory leak

    I have more question just ask why batch file back in before the current ordering process properly release the .exe file, I see that some memory is not released at all. In other words, once again, I create and execute processes in the loop (here, to i