JDO / GAE:创建oneToMany关系时的NucleusObjectNotFoundException

时间:2014-06-01 18:29:12

标签: google-app-engine google-cloud-datastore jdo datanucleus

我有两个实体:CustomerRelation 客户(X)可以与多个客户建立联系。 另一位客户(Y)可以与X的相同客户(或非客户)建立联系。我还需要开始日期和关系状态。

我决定使用Unowned OneToMany关系。

// Customer entity
@PersistenceCapable(detachable = "true")
public class Customer implements Serializable {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private Set<Relation> relations = new HashSet<Relation>();

    // other fields, getters and setters here
}

// --------------------------------------------------------

// Relation entity
@PersistenceCapable(detachable = "true")
public class Relation implements Serializable {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    // Customer who wants to be connected to another customer
    @Persistent
    private Key sourceKey;

    // Customer who needs to accept the request
    @Persistent
    private Key targetKey;

    @Persistent
    private Date date;

    @Persistent
    private String status;
    // other fields, getters and setters here
}

然后我创建了两个客户......并尝试在他们之间建立关系:

PersistenceManager pm = pmf.getPersistenceManager();

// retrives the 2 customers by name 
// 
// ...

// Creating a relationship between them

relation = new Relation();
relation.setDate(new Date());
relation.setStatus("AWAITING");

// first customer key
relation.setSourceKey(customerFindByName.getKey());

// second customer
relation.setTargetKey(targetFindByName.getKey());

// add relation
customerFindByName.addRelation(relation);
targetFindByName.addRelation(relation);

pm.makePersistent(relation);

但我在此行NucleusObjectNotFoundException

pm.makePersistent(relation);


遇到此例外(Could not retrieve entity of kind Relation with key Customer(5066549580791808)/Relation(4785074604081152) org.datanucleus.exceptions.NucleusObjectNotFoundException: Could not retrieve entity of kind Relation with key Customer(5066549580791808)/Relation(4785074604081152) at com.google.appengine.datanucleus.DatastoreExceptionTranslator.wrapEntityNotFoundException(DatastoreExceptionTranslator.java:61) at com.google.appengine.datanucleus.EntityUtils.getEntityFromDatastore(EntityUtils.java:670) at com.google.appengine.datanucleus.DatastorePersistenceHandler.fetchObject(DatastorePersistenceHandler.java:543) at org.datanucleus.state.JDOStateManager.loadFieldsFromDatastore(JDOStateManager.java:1638) at org.datanucleus.state.JDOStateManager.refreshLoadedFields(JDOStateManager.java:1541) at org.datanucleus.api.jdo.state.Hollow.transitionMakeTransactional(Hollow.java:71) at org.datanucleus.state.JDOStateManager.attachCopy(JDOStateManager.java:3194) at org.datanucleus.ObjectManagerImpl.attachObjectCopy(ObjectManagerImpl.java:2488) at org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1818) at org.datanucleus.ObjectManagerImpl.persistObjectWork(ObjectManagerImpl.java:1745) at org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java:1602) at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:731) at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:756) at com.clebettre.social.datastore.CustomerDatastoreImpl.relationRequestAwaiting(CustomerDatastoreImpl.java:139) at com.clebettre.social.services.customer.CustomerServiceImpl.relationRequestAwaiting(CustomerServiceImpl.java:51) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at com.sun.proxy.$Proxy23.relationRequestAwaiting(Unknown Source) at com.clebettre.social.web.relation.RelationController.relationRequestAwaiting(RelationController.java:38)

我不明白为什么我得到这个例外,我想对此有一些解释,以及如何解决这个错误以便正确地保持我的关系?

感谢您的帮助。

0 个答案:

没有答案