使用集合查询

时间:2012-10-13 07:45:37

标签: java google-app-engine objectify

我有这个实体,我需要查询:

@Entity
public class Resource implements Serializable {   
    @Id    
    private Long id;
    private List<String> key;
}

以下是查询:

List<String> keyPath = key.getFullPath();
Resource result = ofy().load().type(Resource.class).filter("key =", keyPath).first().get();

我收到了这个错误:

java.lang.IllegalArgumentException: A collection of values is not allowed.
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:140)
    at com.google.appengine.api.datastore.Query$FilterPredicate.<init>(Query.java:867)

问题:

  • 是否可以使用像List这样的集合作为查询值来进行查询?
  • 是否可以使用Objectify查询或本机数据存储区查询?
  • 如果没有,进行此类查询的方法是什么

我们的想法是查询获取具有与查询值相同的字符串列表(Resource字段)的key实体。

2 个答案:

答案 0 :(得分:1)

您是否尝试使用IN运营商?

Resource result = ofy().load().type(Resource.class).filter("key IN ", keyPath).first().get();

答案 1 :(得分:0)

这是从数据存储区检索信息的解决方案,其中包含具有列表的属性的单个值(使用Objectify),

Query<Resource> resultset = ofy().load().type(Resource.class).filter("key",keyPath);
Resource firstResult = resultset.first().now();