按“键”字段过滤 Objectify 查询

lea*_*ner 5 google-app-engine filter objectify google-cloud-endpoints google-cloud-datastore

我有以下 Objectify 关系:

@Entity(“Author”)
public class Author{
  @Id
  private long authorId;
  …

}

@Entity(“Book”)
public class Book{
  @Id
  private long id;
  private Key<Author> authorKey;
  …

}
Run Code Online (Sandbox Code Playgroud)

现在是有趣的部分:我有authorId(id,不是实体),我需要为该作者查询 Book。我的查询在下面,但它返回一个空列表,而我知道该作者在数据存储区中有书籍。那么我该如何解决这个查询呢?

public static List<Book> getBooksForAuthor(Long authorId) {
    Key<Author> authorKey = Key.create(Author.class, authorId);
    return OfyService.ofy().load().type(Book.class).filter("authorKey", authorKey).order(“-date").list();
  }
Run Code Online (Sandbox Code Playgroud)