Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objectify 4 Filter not working

I'm trying to do a simple JUnit test to do a query like this:

Resource result = ofy().load().type(Resource.class).filter("raw =", 
    "/Bob/-/userId/-/").first().get(); 
if (result != null){
    System.out.println("Resulting Resource raw =" + result.getRaw());
} 

The query above results to null, however when I do a query using id (which is a Long type) I get the result. When I persisted the entity I'm trying to query I logged the @Id and the value is 1, so I did a query using id to check:

Resource result = 
    ofy().load().type(Resource.class).filter("id =", 1).first().get(); 
if (result != null){
    System.out.println("Resulting Resource raw =" + result.getRaw());
}

The resulting result.getRaw() is /Bob/-/userId/-/ which is really weird, from my first query the result should have not been null?

like image 220
quarks Avatar asked Dec 27 '22 16:12

quarks


1 Answers

Check if you Have an @Index on that field, If you try to select by field that doesn't have an index you'll get null even that it is there. On several fields you'll need index on all of them of course.

*Index of more than one field will be placed in the datastore-indexes.xml https://cloud.google.com/appengine/docs/java/config/indexconfig

like image 91
Vini Avatar answered Jan 11 '23 15:01

Vini