尝试在 GAE 中获取子对象时出现 JDOObjectNotFoundException
我设计了一个数据模型,其中有父母和孩子对象(一对多)。首先,我手动完成了所有工作,并将父母的 ID 存储在子对象中以保持关系。然后我决定使用与应用程序引擎文档的关系。现在我有一个 ID 为 21 的父母和一个 ID 为 1 的孩子(我认为 ID 是 1,因为这个孩子是该父母唯一的也是第一个孩子)。现在我正在尝试获取密钥: child.getKey()
使用相同的字符串,我尝试使用以下方法获取对象:
Child child = pm.getObjectById(Child.class, key);
不知怎的,我得到这个错误: 警告:/admin.jsp javax.jdo.JDOObjectNotFoundException: 无法使用键 Child("Parent(21)/Child(1)") 检索 Child 类型的实体
我知道该子项存在于该父项中。也许有人可以帮助我吗?我对此进行了研究,但没有任何结果......
I have designed a data model where there are parents and children objects (one to many). First I did all the job manually and stored ID's of parents in children objects to keep the relation. Then I decided to use relationship with documentations of app engine. Now I have a parent with ID 21 and a child with ID 1 (I suppose ID is 1 because this child is the only and the first child of this parent). Now I am trying to get the key as:
child.getKey()
And with the same String I am trying to get the object with:
Child child = pm.getObjectById(Child.class, key);
Somehow I get this error:
WARNING: /admin.jsp
javax.jdo.JDOObjectNotFoundException: Could not retrieve entity of kind Child with key Child("Parent(21)/Child(1)")
I know that this child exists in this parent. Can maybe someone help me? I have researched about this and nothing showed up...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过几个小时的尝试,我找到了解决方案。有两种方法可以解决这个问题。首先,如果您想获取带有键的子对象,请确保该键不是字符串。它应该是一个密钥 (com.google.appengine.api.datastore.Key)。您可以通过两种不同的方式获取此密钥:
或
然后您可以轻松使用:
I have found the solution after hours of trying every possiblity. There are 2 ways how to solve this problem. First of all if you want to get a child object with the key, be sure that key is not a String. It should be a Key (com.google.appengine.api.datastore.Key). You can get this key in 2 different ways:
or
Then you can easily use: