Search code examples
javagoogle-app-enginefilterjdo

Java GAE: Can I filter by comparing the properties of entities?


I need to query entities having equal properties, for example:

class Relation {
  Integer a;
  Integer b;
}

Query q = pm.newQuery(Relation.class);
q.setFilter("a == b");

The above query returns empty list and I haven't found any way to accomplish this task.


Solution

  • Looking into the documentation for datastore queries, it states clearly that :

    The property value must be supplied by the application; it cannot refer to or be calculated in terms of other properties.

    So what you're trying to do is impossible.

    One thing you COULD do is this :

    1- add a third property to your entity (say a boolean called "equals").

    2- Whenever you update your entity, you check if a == b.

    3- You update "equals" according to the check made in 2.

    4- To query, you look where equals == true.