Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objectify 5.1 Context Not Started Error due to missing ObjectifyFilter

with the latest version of Objectify (5.1), am getting following error when i try to access the ofy() method

You have not started an Objectify context. You are probably missing the ObjectifyFilter. If you are not running in the context of an http request, see the ObjectifyService.run() method.

i am running it from appengine web application, same code and configuration worked fine in older versions

following is my configuration, similar to the example provided in objectify documentation

web.xml

<filter>
    <filter-name>ObjectifyFilter</filter-name>
    <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>ObjectifyFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

OfyService class

public class OfyService {

static {
    long start = System.currentTimeMillis();

    factory().register(User.class);

    log.info(" Entity Registration took : {} ms", (System.currentTimeMillis() - start));
}

public static Objectify ofy() {
    return ObjectifyService.ofy();
}

public static ObjectifyFactory factory() {
    return (ObjectifyFactory) ObjectifyService.factory();
}
}

but i do defined ObjectifyFilter , any idea why am i getting this error? and how can i fix it?

Thanks!

UPDATE:

I have updated the objectify version to v5.1.5 but still the issue is not resolved any update on this?

like image 544
Ramesh Lingappa Avatar asked Oct 26 '14 19:10

Ramesh Lingappa


1 Answers

make sure your StartupActions class looks like:

@Start(order=100)
public void generateDummyDataWhenInTest() {
    if (ninjaProperties.isDev()) {
        try (Closeable closeable = ObjectifyService.begin()) {
            ObjectifyProvider.setup();
        } catch (IOException ex) {
            Logger.getLogger(StartupActions.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }
}

We should have fixed that long ago in the archetype, but it's not really high on the prio list. It would be awesome if you could push a PR :)

like image 135
Ra_ Avatar answered Nov 13 '22 22:11

Ra_