我可以将子对象保留在父类的 @PrePersist 处理程序中吗? (客观化 3.1b1)
我是 Objectify 的新手,正在尝试实现一对多关系。我有实体组织和实体人。组织具有 @Transient
属性 List<人>联系人员。 Person 类具有 @Parent
属性 Key<组织> OrganizationKey 我可以通过设置器设置。
我想将 contactPeople 保留在组织的 @PrePersist
处理程序中。为此,我需要在 Person 中设置父密钥。
Wiki 此处说:“您无法更新@PrePersist 回调中的 @Id 或 @Parent 字段;此时,低级实体已经使用完整的 Key 构造完成,因此可以将其作为可选参数传入。”
我不确定这是还是准确的信息?因为我在 PrePersist
处理程序中获取的 com.google.appengine.api.datastore.Entity
对象的键的字面意思是“no-id-yet”。
您将如何实施?
谢谢你!
2011 年 11 月 17 日更新:
在新的 Objectify4 中,我们将能够建立如下所示的半自动关系:
class Beastie {
@Parent
@Load
ParentThing parent;
@Id Long id;
@Load({"bigGroup", "smallGroup"})
SomeThing some;
@Load("bigGroup")
List<OtherThing> others;
@Load
Ref<OtherThing> refToOtherThing;
Ref<OtherThing> anotherRef; // this one is never fetched automatically
}
这里是新版本的不断演变的设计文档。
这是个大新闻。 Twig 作者 John Patterson 今天加入了 Objectify 项目。
I am new to Objectify and trying to implement One-to-Many relationship. I have entities Organization and entity Person. Organization has @Transient
property List< Person > contactPeople. Class Person has @Parent
property Key< Organization > organizationKey which I can set via setter.
I'd like to persist contactPeople in @PrePersist
handler of Organization. In order to do that I need to set parent key in Person.
Wiki here says: "You can't update @Id or @Parent fields in a @PrePersist callback; by this time, the low-level Entity has already been constructed with a complete Key so it can be passed in as an optional parameter."
I'm not sure this is still accurate information ? Because key of com.google.appengine.api.datastore.Entity
object that I get in PrePersist
handler has key that literally says "no-id-yet".
How would you implement this ?
Thank you!
Update at Nov 17, 2011:
In new Objectify4 we'll be able to do semi-automatic relationships like this:
class Beastie {
@Parent
@Load
ParentThing parent;
@Id Long id;
@Load({"bigGroup", "smallGroup"})
SomeThing some;
@Load("bigGroup")
List<OtherThing> others;
@Load
Ref<OtherThing> refToOtherThing;
Ref<OtherThing> anotherRef; // this one is never fetched automatically
}
Here is evolving design document of new version.
This is big news. Twig author, John Patterson, joined Objectify project today.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,看来你需要在你的数据模型前面创建一个 Dao。因此,您将能够执行以下操作:
GAE+Objectify 需要您自己的代码处理很多事情,因此这是很常见的事情
Hm, seems that you need to make an Dao in front of your data models. So, you will able to do something like:
GAE+Objectify requires a lot of thing to handle by your own code, so it's a common thing