Hi,

I'm working on an integration test for a Java SE application.

Here's what I'm basically doing:

*# Phase 1:*

Injector i1 = Guice.createInjector(..., new JpaPersistModule("myUnit")); // 
all done in my module, but nothing fancy here

// bootstrap some instances
PersistService persistService = i1.getInstance(PersistService.class);
UserService service = i1.getInstance(UserService.class);

// start persist
persistService.start();

// populate database
service.createUser(foo, bar);
...

// stop persist
persistService.stop;
i1 = null;

*# Phase 2:*

Injector i2 = Guice.createInjector(..., new JpaPersistModule("myUnit")); // 
all done in my module, but nothing fancy here

// bootstrap some instances
PersistService persistService = i2.getInstance(PersistService.class);
MyApplication app = i2.getInstance(MyApplication.class);

// start persist
persistService.start();

// do some work
app.doSomethingUseful(); <-- doesn't work

This time I get the following Exception:
java.lang.IllegalStateException: Attempting to execute an operation on a 
closed EntityManagerFactory.
    at 
org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.verifyOpen(EntityManagerFactoryDelegate.java:306)
 
~[org.eclipse.persistence.jpa-2.4.1.jar:na]
    at 
org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
 
~[org.eclipse.persistence.jpa-2.4.1.jar:na]
    at 
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:304)
 
~[org.eclipse.persistence.jpa-2.4.1.jar:na]
    at 
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:282)
 
~[org.eclipse.persistence.jpa-2.4.1.jar:na]
    at 
com.google.inject.persist.jpa.JpaPersistService.begin(JpaPersistService.java:70)
 
~[guice-persist-3.0.jar:na]
    at 
com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:49)
 
~[guice-persist-3.0.jar:na]

After debugging it turned out that the highlighted JpaLocalTxnInterceptor 
got the JpaPersistService from phase 1 injected, which is (of course) 
already closed.

Any idea what happended here? I "fixed" it by removing the 
persistService.stop() call in phase 1, but I'm not sure if this behaviour 
is to be expected...

Thanks,
Marian

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to