Guice-Persist: Attempting to execute an operation on a closed EntityManager

1,760 views
Skip to first unread message

Carlos Alexandro Becker

unread,
May 3, 2012, 8:53:27 AM5/3/12
to google...@googlegroups.com

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?

scl

unread,
May 3, 2012, 4:37:29 PM5/3/12
to google...@googlegroups.com
two questions:

1)
Do these multiple calls to your DAO method happen in the same request or in separate requests?

2)
do you call anywhere in your code one of the following methods?
 - PersistService.stop()
 - UnitOfWork.end()
 - EntityManager.close()
 - EntityManagerFactory.close()


Alen Vrečko

unread,
May 3, 2012, 5:53:34 PM5/3/12
to google-guice
I found guice-persist to have broken txn semantics. I didn't had time
to investigate. I went back with using warp-persist which works great!

I'd build warp-persist from source http://code.google.com/p/warp-persist/source/checkout.
It has a well documented txn semantics and they work as explained.
http://www.wideplay.com/guicewebextensions2

In any case I suspect you do @Inject EntityManager but what you should
really do is @Inject Provider<EntityManager> this is a major
difference.

Cheers
Alen

Carlos Alexandro Becker

unread,
May 4, 2012, 10:42:16 AM5/4/12
to google...@googlegroups.com
Thanks, Alen. 

I just changed like you said and it worked like a charm :)
Reply all
Reply to author
Forward
0 new messages