在HBase上的Datanuclues合并不起作用(序列化(分离)对象)

时间:2012-08-31 12:13:39

标签: jpa hbase datanucleus

我在尝试合并其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关键字创建,而不是之前从数据库中提取的。

非常感谢任何帮助。

提前致谢!

1 个答案:

答案 0 :(得分:1)

如果您尝试合并序列化对象

,请在 persistence.xml 中设置 datanucleus.allowAttachOfTransient = true