Java JDO关系-应用程序引擎

Java JDO关系-应用程序引擎,java,google-app-engine,jdo,Java,Google App Engine,Jdo,我想为我的食谱实现一个简单的分类系统 以下是我的配方实体: @PersistenceCapable public class Recipe { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key; @Persistent private List<Category> categories; public Recipe

我想为我的食谱实现一个简单的分类系统

以下是我的配方实体:

@PersistenceCapable
public class Recipe {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private List<Category> categories;

    public Recipe(List<Category> categories) {
        this.categories = categories;
    }
    ...
}
现在,正如您所看到的,关联很简单。当我创建一个
配方
时,我确保用一个类别列表来构建它。这太棒了。在我的网站上,我可以迭代一个
配方
列表(或其他什么),然后在上面执行
.getCategories()
来检索我需要的类别

但是,假设我想检索数据存储中的所有类别,当我单击一个类别时,我希望能够检索该类别的所有配方。最简单的方法是什么

要显示我拥有的所有类别:
请按名称从Category.class组中选择。

但是如何检索给定类别下的所有食谱?我的JDO设计有缺陷吗?

从mydomain.Recipe中选择category=:category


不知道这个“JDO有缺陷”的想法是什么。。。JDO只提供透明的持久性,并允许您根据需要设计类。

其中category=:category
-我的
配方
类中没有
类别
字段。从mydomain中选择。配方WHERE categories.contains(:category)返回包含特定类别的所有配方。确定,但是什么是
:类别
?类别对象?Java中键入collField.contains(element)时的类别键是什么元素?收藏中包含的东西。当然是一类。这就是JDOQL的全部要点,它遵循Java
:category
是一个存放单词的地方,当您在
查询中调用
execute
时可以定义这个单词。
@PersistenceCapable
public class Category {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private String name;

    public Category(String name) {
        this.name = name;
    }
    ...
}