Reputation: 3911
I'm following the docs on this site: http://code.google.com/intl/sv-SE/appengine/docs/java/datastore/jdo/queries.html
From there I learned how to make queries but I seems only to work with one parameter. Here's how I'm doing it successfully:
javax.jdo.Query q1 = pm.newQuery(Player.class);
q1.setFilter("isOpen == true");
List<Player> players = (List<Player>) q1.execute();
That fetches me all the Player object with the boolean isOpen == true. I can do the same thing with a Long, that works too.
Here's the problem: When combining two conditions like this:
javax.jdo.Query q1 = pm.newQuery(Player.class);
q1.setFilter("isOpen == true && lastPing > 100");
List<Player> players = (List<Player>) q1.execute();
The app crashes. Here's the error I'm getting:
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
So, does anyone know why this is happening? Any help is greatly appreciated.
Upvotes: 1
Views: 955
Reputation: 23171
You can't do an inequality filter along with another filter unless you have an index on the column for which you're doing the inequality comparison. Add this to your datastore-indexes.xml
in your WEB-INF
folder and deploy it (either a full deploy or appcfg update-indexes):
<datastore-index kind="Player" ancestor="false">
<property name="isOpen" direction="asc"/>
<property name="lastPing" direction="asc"/>
</datastore-index>
Upvotes: 3