Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter by key in App Engine datastore in Java

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.

like image 656
Robin Green Avatar asked Feb 19 '23 06:02

Robin Green


1 Answers

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.

like image 111
Peter Knego Avatar answered Feb 23 '23 02:02

Peter Knego