如何在一个实体组中创建实体?
我正在构建一个基于谷歌应用程序引擎(Java)的应用程序,使用 JDO 进行持久化。
有人可以给我一个例子或者给我指出一些代码,这些代码显示在事务中使用 javax.jdo.PersistenceManager.makePersistenceAll() 持久化多个实体(相同类型)。
基本上我需要了解如何将多个实体放入一个实体组中,以便可以在事务内使用 makePersistentAll() 保存它们。
I am building an app based on google app engine (Java) using JDO for persistence.
Can someone give me an example or a point me to some code which shows persisting of multiple entities (of same type) using javax.jdo.PersistenceManager.makePersistentAll() within a transaction.
Basically I need to understand how to put multiple entites in one Entity Group so that they can be saved using makePersistentAll() inside transaction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
本文档的这一部分正是针对此问题进行处理的。
This section of the docs deals with exactly that.
我这样做了:
...
所以一个典型的数据存储持久对象将在构造函数中设置 id,而不是自动获取 id
,并且您将 root_key 作为父级传递,
我不确定是否可以将不同的父级传递给同类对象
i did this:
...
so a typical datastore persistent object will set the id in the constructor instead of getting one automatically
and you pass root_key as the parent
i'm not sure if you can pass different parents to objects of the same kind
感谢尼克的回复。
本文档仅介绍应用程序引擎在存在父子关系时对实体组的隐式处理。我想在事务中使用 PeristentManager.makePersistentAll(list) 保存多个相同类型的对象。如果对象不是同一实体组,则会引发异常。目前我可以按如下方式执行此操作,但认为必须有一个更好、更合适的方法来执行此操作 -
尽管此方法有效,但问题在于您必须依赖于已经持久的实体来创建实体组。
Thanks for the response Nick.
This document only tells about implicit handling of entity groups by app engine when its a parent-child relationship. I want to save multiple objects of same type using PeristentManager.makePersistentAll(list) within a transaction. If objects are not same Entity Group this throws exception. Currently I could do it as below but think there must be a better and more appropriate approach to do this -
Although this approach works, the problem with this is that you have to depend on an already persistent entity to create an entity group.
Gopi,据我所知,您不必这样做...这应该有效(尚未测试):
同样,据我所知,这应该将所有这些对象放在同一个实体组中。我很想知道我是否错了。
Gopi, AFAIK you don't have to do that... this should work (haven't tested it):
Again, AFAIK, this should put all these objects in the same entity group. I'd love to know if I am wrong.