我有一个名为'token'的属性值列表。我正在尝试过滤一种实体
这就是我的尝试。
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);
但是我收到以下错误消息。
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)
我之前遇到过类似的问题,但它有效,因为过滤条件是另一种方式,即this.token.contains(tokens),其中'token'是实体的一部分,属于List of String。但我不确定为什么这不起作用。有人可以帮助我吗?
答案 0 :(得分:1)
你声明一些名为&#34;令牌的变量&#34;然后传入一个参数(大概是你打算成为令牌变量)。变量不是参数,它们是不同的。使用显式参数或隐式参数(带:前缀),就像任何体面的JDO文档会告诉你的那样