Guido
Guido

Reputation: 47685

GAE/J datastore : how to build an IN query with JDO

I am trying to query a collection of entities by its key in the Google App Engine datastore. This is the query I am trying to execute with no success:

Query query = pm.newQuery(Fix.class);
query.setFilter("__key__ IN param");
query.declareParameters("com.google.appengine.api.datastore.Key param");
query.execute(list); // list is an array of keys

And the error I get is:

javax.jdo.JDOUserException: Portion of expression could not be parsed: IN param

Is it possible to use build an IN query with JDO or the low level API that finds entities by key?

Upvotes: 1

Views: 1301

Answers (2)

Peter Recore
Peter Recore

Reputation: 14187

I think you might be confusing the JDO and JPA syntax: see examples on this page

JPA:

select from Person where
    favoriteFood IN ('cheeseburger', 'pizza', 'fried chicken')
    order by favoriteFood, age

JDO:

Query q = pm.newQuery(
    "select from Person where :p1.contains(favoriteFood) order by favoriteFood, age");
q.execute(Arrays.asList("cheeseburger", "pizza", "fried chicken"));

Upvotes: 3

rodion
rodion

Reputation: 15029

Have you tried examples from this page? Something like:

query.addFilter("__key__", Query.FilterOperator.IN, param);

Note that param should be a list.

Upvotes: 0

Related Questions