0
votes

I am trying to load an entity by id to check if it exists. If I call as below it returns null:

String idS = lat+lon+lang;
GeoVars response = ofy().load().type(GeoVars.class).id(idS).now(); //Always returns null

If I turn off the cache it returns the entitiy:

GeoVars response = ofy().cache(false).load().type(GeoVars.class).id(idS).now(); //Returns OK

And here is the GeoVars class:

@Entity
@Cache
public class GeoVars {
    @Id String id;
    String summary;
    String something;
    String another;
    String blabla;
    String lang;
    int day;

I understand that memcache is "best effort" basis but even it is not cached, it should take the entity from datastore automatically? Why does load return null?

EDIT:

When I try with safe, also returns null.

    try {
        response = ofy().load().type(GeoVars.class).id(idS).safe();
    } catch (com.googlecode.objectify.NotFoundException e) {
        e.printStackTrace();
        response = createResponse(idS, lat, lon, lang, dayofweek);
        ofy().save().entity(response);
    }
1
What version of Objectify are you using and what happens if you change now() to safe()? - tx802
@tx802 I am using v5. I will try and inform what happens with safe() but normally I need the null value to create if it doesn't exist. - savante
You could put the creation code inside the catch(NotFoundException) block. - tx802
I tried, same thing happens. You can see the edit above. - savante
@tx802 any ideas? I am really stuck! - savante

1 Answers

0
votes

It turns out that I forgot to put ObjectifyFilter to web.xml. Now it works all fine.