I get the exception when trying to merge an entity whose Id matches the corresponding datastore entity already in HBase:
javax.persistence.PersistenceException: Object "ai.ilikeplaces.entities.Wall@4aaf0d" being inserted has id "12653" yet an object with this id already exists in the datastore!
at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:30
2)
at org.datanucleus.api.jpa.JPAEntityManager.merge(JPAEntityManager.java:568)
at ai.ilikeplaces.util.cache.AbstractHCMapStore.store(AbstractHCMapStore.java:39)
at ai.ilikeplaces.logic.crud.hazelcast.HazelcastWallMapStore.store(HazelcastWallMapStore.java:20)
at com.hazelcast.impl.concurrentmap.MapStoreWrapper.store(MapStoreWrapper.java:110)
at com.hazelcast.impl.CMap$1.run(CMap.java:994)
at com.hazelcast.impl.executor.ParallelExecutorService$ParallelExecutorImpl$ExecutionSegment.run(ParallelExecutorService.java:212)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
Caused by: org.datanucleus.exceptions.NucleusUserException: Object "ai.ilikeplaces.entities.Wall@4aaf0d" being inserted has id "12653" yet an object with this id already exists in the datastore!
at org.datanucleus.store.hbase.HBasePersistenceHandler.insertObject(HBasePersistenceHandler.java:129)
at org.datanucleus.state.JDOStateManager.internalMakePersistent(JDOStateManager.java:2371)
at org.datanucleus.state.JDOStateManager.makePersistent(JDOStateManager.java:2347)
at org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1798)
at org.datanucleus.ObjectManagerImpl.persistObjectWork(ObjectManagerImpl.java:1647)
at org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java:1504)
at org.datanucleus.api.jpa.JPAEntityManager.merge(JPAEntityManager.java:564)
... 8 more
When attempting to merge an entity.
The code related to this exception is:
System.out.println("Attempting to store data:" + value);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("adimpression_ilikeplaces_war_1.6-SNAPSHOTPU_DN");
System.out.println("Obtained EntityManagerFactory.");
EntityManager em = emf.createEntityManager();
System.out.println("Obtained EntityManager.");
em.getTransaction().begin();
System.out.println("Began Transaction.");
em.merge(value);
System.out.println("Persisted data.");
em.getTransaction().commit();
System.out.println("Committed Transaction");
where
em.merge(value);
is line 39. That is AbstractHCMapStore.java:39 .
The entity I am trying to merge is a new entity, i.e. created with java new keyword and not fetched from database previously.
Any help would be greatly appreciated.
Thanks in advance!
Set datanucleus.allowAttachOfTransient=true in persistence.xml if you’re trying to merge a serialized object