2
votes

I have an app managed by maven with two modules: one for persistence, and another for the webapp itself (gwt).

My tests in persistence module works like a charm, but, in webapp, when I execute the same method multiple times I got a java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager..

I use guice-persist to inject the entity manager into my DAOs, and all my DAO methods have the @Transactional annotation.

In my webapp, I put a: public class ScuvServletModule extends ServletModule {

    @Override
    protected void configureServlets() {
       super.configureServlets();
       install(MyPersistenceAPI.getModule()); // return my module and install it
       filter("/*").through(PersistFilter.class);
       /// another bindings...
    }
}

If I remove the PersistFilter, it wotks, but randomly throws a Transaction Closed exception or something like that.

Any help?

1

1 Answers

3
votes

I found the problem. It is the PersistFilter. Aparently, its a Singleton, my DAOs are singletons too, but the EntityManager isnt.

So, now I inject a Provider<EntityManager> instead EntityManager, and it works just like a charm.