Ravi
Ravi

Reputation: 4009

Objectify app engine - querying embedded entities using a list of values

I am using objectify-appengine framework for querying. Here is my simplified problem: Consider these 2 classes:-

public class Customer {
    @Id private String email;
    @Embedded private Account Account = new Account(); // note embedded annotation
}

and

public class Account {
   private String number;  //example: 1234
}

The following query works & gives me 1 customer:

Objectify ofy = ObjectifyService.begin();
ofy.query(Customer.class).filter("account.number = ", "1234");

Question:

However, if have a List of values (account numbers). Is there a way to fetch them in 1 query? I tried passing a list of account numbers like this:

ofy.query(Customer.class).filter("account.number = ", myAccountNumberList);

But if fails saying: java.lang.IllegalArgumentException: A collection of values is not allowed.

Thoughts?

Upvotes: 0

Views: 1918

Answers (1)

stickfigure
stickfigure

Reputation: 13556

filter("account.number IN", theList)

Note that IN just causes the GAE SDK to issue multiple queries for you, merging the results:

The IN operator also performs multiple queries, one for each item in the specified list, with all other filters the same and the IN filter replaced with an EQUAL filter. The results are merged, in the order of the items in the list. If a query has more than one IN filter, it is performed as multiple queries, one for each possible combination of values in the IN lists.

From https://developers.google.com/appengine/docs/java/datastore/queries

Upvotes: 1

Related Questions