【发布时间】:2018-04-26 00:33:06
【问题描述】:
我有一个系统,我试图最小化 Datastore 写入次数(谁不会?),同时使用祖先关系。考虑以下简化类:
public class Ancestor {
@Id
private String id;
private String field;
private Ref<Descendant> descendantRef;
public Descendant getDescendant() {
return this.descendantRef.get();
}
public void setDescendant(Descendant des) {
this.descendantRef = Ref.create(des);
}
}
public class Descendant {
@Id
private String id;
private String field;
@Parent
private Key parent;
}
我的问题:即使我设置了后代 ref,在保存 Ancestor 实体时,也会保存 null,但如果我也保存后代,Objectify 会抱怨 Attempted to save a null entity。
我的问题:我收集到 Objectify 使用 @Load 注释优化了 get() 操作的顺序,所以有没有办法让它在 save() 操作上也做同样的事情,所以到时候Ancestor 正在发送到 Datastore,Descendant ref 是否已正确填充?
提前感谢您的任何建议!
【问题讨论】:
-
您是在问如何在保存多个 Ancestor 时优化 descendantRef 的 save() 操作吗?
-
@Ajeet 更像是如果有办法只在祖先上调用
save(),并让 Objectify 优化类似于加载图的“保存图”并首先保存 Descendant,构造 Ref ,并以此拯救祖先。这很可能是不可能的。除此之外,如果有办法自动构造一个descendantRef,及时将Ancestor与ref一起保存......
标签: google-app-engine objectify