gpt4 book ai didi

java - 在Java中使用JDO在GAE中查询时如何设置多个参数?

转载 作者:行者123 更新时间:2023-11-29 06:06:41 25 4
gpt4 key购买 nike

我正在关注此站点上的文档:http://code.google.com/intl/sv-SE/appengine/docs/java/datastore/jdo/queries.html

从那里我学会了如何进行查询,但我似乎只使用一个参数。以下是我如何成功地做到这一点:

javax.jdo.Query q1 = pm.newQuery(Player.class);

q1.setFilter("isOpen == true");

List<Player> players = (List<Player>) q1.execute();

这为我获取了所有具有 boolean 值 isOpen == true 的 Player 对象。我可以用 Long 做同样的事情,这也行。

问题是:当像这样组合两个条件时:

javax.jdo.Query q1 = pm.newQuery(Player.class);

q1.setFilter("isOpen == true && lastPing > 100");

List<Player> players = (List<Player>) q1.execute();

应用程序崩溃。这是我收到的错误:

Uncaught exception from servlet com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found. The suggested index for this query is: datastore-index kind="Player" ancestor="false" source="manual" property name="isOpen" direction="asc" property name="lastPing" direction="asc" datastore-index

所以,有人知道为什么会这样吗?非常感谢任何帮助。

最佳答案

除非在要进行不等式比较的列上有索引,否则您不能将不等式筛选器与另一个筛选器一起执行。将此添加到 WEB-INF 文件夹中的 datastore-indexes.xml 并部署它(完全部署或 appcfg update-indexes):

<datastore-index kind="Player" ancestor="false">
<property name="isOpen" direction="asc"/>
<property name="lastPing" direction="asc"/>
</datastore-index>

关于java - 在Java中使用JDO在GAE中查询时如何设置多个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8311861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com