Ref.get 返回 null

Ref.get returning null

我正在为我的下一个项目学习 google 带有数据存储的应用引擎。我为此制作了一个示例应用程序。

下面是实体的代码:

@Entity
public class Quote {
    @Id
    private Long id;
    @Parent @Load
    private Ref<Author> author;

    public Quote() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Author getAuther() {
        return author.get();
    }

    public void setAuther(Author author) {
        this.author = Ref.create(author);
    }
}

@Entity
public class Author {
    @Id
    private Long id;
    String name;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

我正在使用此 API

插入引述
 @ApiMethod(
            name = "insert",
            path = "quote",
            httpMethod = ApiMethod.HttpMethod.POST)
    public Quote insert(Quote quote) {
        ofy().save().entity(quote).now();
        return ofy().load().entity(quote).now();
    }

当我尝试插入新引号时,我的 author.get() 为空。一直卡在这个问题上,无法继续学习。

谢谢。

我没有在插入 Quote 之前插入 Auther。您可以将其隐藏在实体模型中,也可以在 API 调用中单独执行。