简体   繁体   English

带有字符串列表的Google App Engine查询

[英]Google app engine query with a list of string

I have a list of property values named 'token'. 我有一个名为“ token”的属性值列表。 I am trying to filter an entity of kind 我正在尝试过滤一个实体

This is what i have tried. 这就是我尝试过的。

List<String> tokens = getTokensFrom(invitations);
PersistenceManager pm = this.dataStoreService.getObjectDBConnection();
Query query = pm.newQuery(Invitations.class);
query.setFilter("tokens.contains(token)");
query.declareVariables(List.class.getName() + " tokens");
List<Invitations> invites = (List<Invitations>) query.execute(tokens);

But I'm getting the below error message. 但是我收到以下错误消息。

Problem with query <SELECT FROM com.mypackage.shared.domainobjects.Invitations WHERE tokens.contains(token) VARIABLES java.util.List tokens>: Unsupported method <contains> while parsing expression: InvokeExpression{[VariableExpression{tokens}].contains(PrimaryExpression{token})}
com.google.appengine.datanucleus.query.DatastoreQuery$UnsupportedDatastoreFeatureException: Problem with query <SELECT FROM com.testbudha.shared.domainobjects.PublishedExam WHERE tokens.contains(token) VARIABLES java.util.Collection tokens>: Unsupported method <contains> while parsing expression: InvokeExpression{[VariableExpression{tokens}].contains(PrimaryExpression{token})}
    at com.google.appengine.datanucleus.query.DatastoreQuery.newUnsupportedQueryMethodException(DatastoreQuery.java:993)
    at com.google.appengine.datanucleus.query.DatastoreQuery.handleContainsOperation(DatastoreQuery.java:971)
    at com.google.appengine.datanucleus.query.DatastoreQuery.addExpression(DatastoreQuery.java:830)
    at com.google.appengine.datanucleus.query.DatastoreQuery.addFilters(DatastoreQuery.java:739)
    at com.google.appengine.datanucleus.query.DatastoreQuery.compile(DatastoreQuery.java:248)
    at com.google.appengine.datanucleus.query.JDOQLQuery.performExecute(JDOQLQuery.java:158)
    at org.datanucleus.store.query.Query.executeQuery(Query.java:1789)
    at org.datanucleus.store.query.Query.executeWithArray(Query.java:1666)
    at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:243)

I had a similar problem previously but it works because the filter criteria was the other way round ie this.token.contains(tokens) where 'token' was part of the entity and was of type List of String. 之前我也遇到过类似的问题,但是它有效,因为过滤条件是相反的,即this.token.contains(tokens),其中“ token”是实体的一部分,类型为String列表。 But I'm not sure why this is not working. 但是我不确定为什么这行不通。 Can someone please help me? 有人可以帮帮我吗?

You declare some variable called "tokens" yet pass in a parameter (presumably what you intended to be the tokens variable). 您声明了一个称为“ tokens”的变量,但传入了一个参数(可能是您打算作为tokens变量)。 A variable is not a parameter, they are different. 变量不是参数,它们是不同的。 Either use an explicit parameter, or an implicit parameter (with : prefix) as any decent JDO docs would tell you 使用任何明确的JDO文档都会告诉您的显式参数或隐式参数(带有:前缀)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM