Objectify Ref<>与@Load无法使用ofy()。load()。group()

时间:2016-12-15 18:14:01

标签: google-app-engine objectify

我有一个问题Ref<>使用@Load。基本上我从Objectify网站制作了一个复制粘贴,用负载组测试@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();其他实体仍然加载到会话中。但是在文档中,它需要加载组类。

1 个答案:

答案 0 :(得分:0)

isLoaded()方法测试实体是否在会话缓存中。由于您只是save()实体,它已经在会话缓存中。

如果要测试加载组的行为,则需要ofy().clear()缓存。