I am trying to perform a projection query in order to fetch several properties from each entity in my datastore of over ten thousand entities. I have read and followed the documentation, but my query is not returning any results. I've even simplified my projection down to only projecting a single property, the entity's ID field, but still get 0 results. Here is my simplified code:
Query q = new Query("MyEntity");
q.addProjection(new PropertyProjection("entityId", Long.class));
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
PreparedQuery pq = datastore.prepare(q);
int count = pq.countEntities(FetchOptions.Builder.withLimit(1000));
log.info("query contains " + count + " items.");
When I run this code, count
equals 0. If I simply remove the second line so that the query has no projections, count
equals 1000.
I am using Objectify in my app, but I am using the GAE low-level API for projection queries because I'm using Objectify v3, which doesn't support projection queries. It would be a lot of work to change my code to support Objectify v4.
The entityId
field I'm projecting looks like this in my Objectify entity object:
@Id Long entityId;