【发布时间】:2016-12-15 18:14:00
【问题描述】:
我在使用 @Load 时遇到问题 Ref。基本上,我从 Objectify 网站复制粘贴,以使用 Load Groups 测试 @Load 注释。
@Entity
public static class Thing {
public static class Partial {}
public static class Everything extends Partial {}
public static class Stopper {}
@Id Long id;
@Load(Partial.class) Ref<Other> withPartial;
@Load(Everything.class) Ref<Other> withEveryhthing;
@Load(unless=Stopper.class) Ref<Other> unlessStopper;
public Ref<Other> getWithPartial() {
return withPartial;
}
public void setWithPartial(Ref<Other> withPartial) {
this.withPartial = withPartial;
}
public Ref<Other> getWithEveryhthing() {
return withEveryhthing;
}
public void setWithEveryhthing(Ref<Other> withEveryhthing) {
this.withEveryhthing = withEveryhthing;
}
public Ref<Other> getUnlessStopper() {
return unlessStopper;
}
public void setUnlessStopper(Ref<Other> unlessStopper) {
this.unlessStopper = unlessStopper;
}
}
然后我写了下面的代码。
Other other = new Other();
Key<Other> otherKey = ofy().save().entity(other).now();
Thing thing = new Thing();
thing.setWithPartial(Ref.create(otherKey));
Key<Thing> thingKey = ofy().save().entity(thing).now();
Thing t = ofy().load().key(thingKey).now();
System.out.println("Is loaded: " + t.getWithPartial().isLoaded());
不写ofy().load().group(Partial.class).key(thingKey).now();其他实体仍加载到会话中。但是在文档中它需要加载组类。
【问题讨论】:
标签: google-app-engine objectify