如何在Java中的Google App Engine数据存储中使用列表属性?

问题描述:

要置于数据存储中的对象将具有一组标记。如何在Java中的Google App Engine数据存储中使用列表属性?

public class Model 
{ 
    List<String> tagList 
    ... 
} 

在Python中,Google App Engine具有列表属性的概念。 Java中的等价概念是什么(如果存在)以及如何在Java中,在JPA和/或JDO中使用列表属性?

+0

我希望答案是不使用Python! – onejigtwojig 2011-04-25 13:06:51

+0

任何人都知道JPA的实现? – onejigtwojig 2011-04-25 15:29:36

+1

除Java提供的JPA和JDO外,还有其他数据访问API选项,例如Objectify。 – topchef 2011-04-25 20:22:41

请参见我的博客文章正是在此:Efficient Keyword Search with Relation Index Entities and Objectify for Google Datastore。它讨论如何使用关系索引实体和对象化来实现使用列表属性进行搜索。

总结:

Query<DocumentKeywords> query = ofy.query(DocumentKeywords.class); 
    for (String keyword : keywords) { 
    query = query.filter("keywords", keyword); 
    } 

    Set<Key<Document>> keys = query.<Document>fetchParentKeys(); 

    Collection<Document> documents = ofy.get(keys).values(); 

其中DocumentKeywords包含所有关键字的列表属性(集合)因其Document实体,并Document实体是DocumentKeywords父。

+1

您的博客文章正是我要找的!谢谢.. – onejigtwojig 2011-04-26 02:59:35

JDO使用

@Persistent 
private List<ContactInfo> contactInfoSets;