【发布时间】:2011-03-15 07:19:11
【问题描述】:
我想为我的食谱实现一个简单的分类系统。
这是我的食谱实体:
@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;
}
...
}
还有我的 Category 实体:
@PersistenceCapable
public class Category {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String name;
public Category(String name) {
this.name = name;
}
...
}
现在您可以看到关联很简单。当我创建Recipe 时,我确保使用类别列表构建它。这很棒。在我的网站上,我可以遍历 Recipe 列表(或其他),然后在其上执行 .getCategories() 以检索我需要的类别。
但是,假设我想检索数据存储中的所有类别,当我单击一个类别时,我希望能够检索该类别的所有食谱。最简单的方法是什么?
显示我拥有的所有类别:select from Category.class group by name。
但是如何检索给定类别下的所有食谱?我的设计对 JDO 有缺陷吗?
【问题讨论】:
标签: java google-app-engine jdo