简体   繁体   中英

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM