【问题标题】:Objectify Ref<> with @Load is not working with ofy().load().group()Objectify Ref<> with @Load 不适用于 ofy().load().group()
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-10-31
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-10
      • 2012-12-11
      相关资源
      最近更新 更多