0

尝试合并其 Id 与 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

尝试合并实体时。

与此异常相关的代码是:

        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");

在哪里

em.merge(value);

是第 39 行。即 AbstractHCMapStore.java:39 。

我要合并的实体是一个新实体,即使用 java new 关键字创建的,以前没有从数据库中获取。

任何帮助将不胜感激。

提前致谢!

4

1 回答 1

1

如果您尝试合并序列化对象,请在persistence.xml中设置datanucleus.allowAttachOfTransient=true

于 2012-11-23T06:05:35.207 回答