【问题标题】:How do you use list properties in Google App Engine datastore in Java?您如何在 Java 中使用 Google App Engine 数据存储中的列表属性?
【发布时间】:2011-08-12 07:48:18
【问题描述】:

要放置在数据存储中的对象将具有一组标签。

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

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

【问题讨论】:

  • 我希望答案是不要使用 Python!
  • 有人知道 JPA 的实现吗?
  • Java 中除了 JPA 和 JDO 之外,还有其他数据访问 API 选项,例如 Objectify。
  • GAE/J 中的 JPA 实现显然是 GAE 自己的 DataNucleus 插件。请注意,虽然它使用的是旧版本的 DataNucleus,并且不会尝试支持所有 JPA 功能,但应该可以使用 BigTable 处理绝大多数功能。

标签: java google-app-engine jpa google-cloud-datastore jdo


【解决方案1】:

请参阅我的博文:Efficient Keyword Search with Relation Index Entities and Objectify for Google Datastore。它讨论了使用关系索引实体和 Objectify 实现具有列表属性的搜索。

总结一下:

  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 的父实体。

【讨论】:

    【解决方案2】:

    JDO 中使用

    @Persistent
    private List<ContactInfo> contactInfoSets;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-16
      相关资源
      最近更新 更多