Prakash Chandra Prakash Chandra - 1 year ago 88
Java Question

Storing and Searching an Array of Strings in Google App Engine DataStore (Java)

I am trying to implement a many to one relationship. I plan to store an array of keys (datastore entity key) of one model in the other model's entity as


e.g. Say 4 entities of Model A (a1,a2,a3,a4) have datastore keys : key1, key2, key3 and key4 respectively. Now I store an entity of Model B which has a property called "ids" as
. "ids" has these
as the elements: key1, key2, key3 and key4.

Its all fine till now.
But how do I query the model B for each of these ids now?

What I want to do is something like this:


Clearly this can not be done right now.
Now what I am doing is fetching the ids property of each B entity and then manually deserializing into a list of string and then checking if the key is present or not.

As you can see this is highly inefficient. How should I approach here? Should I store these mapping in a separate Model. I don't want to handle Joins, but I will have to if I can't get anything else than the present solution.

I am not using JPA or JDO and I plan not to use them.

Any help would be appreciated.

Answer Source

The query with EQUAL filter works fine for lists of values. Make sure you pass correct value when executing this query.

For example, you can store List, if you only use this entity on the server side.

If you need this list on the client side, and you always store keys for entities of the same kind, you can store a list of ids (List) or 'names` (List) used to create these keys. This will take much less space.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download