You would think that this would be an easy question to answer.
How do I, in Java, filter by an entity's key (not a property that just happens to be of type Key
, but its actual key - what we would call the "primary key" in relational database land)?
I don't want to get a single entity with a particular key. I actually do want to do a filter and return a subset of the entities.
The trick is to use Entity.KEY_RESERVED_PROPERTY
in place of property name:
Query q = new Query("MyEntity");
q.setFilter(new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY,
Query.FilterOperator.GREATER_THAN,
KeyFactory.createKey("MyEntity", "somevalue")));
This will find all MyEntity
entities with key greater than somevalue
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With