Hello,
I'm relatively new to guice, and I've got a problem that I quite don't
understand.
I have a webapp based on guice, eclipse link, mysql that runs on a tomcat
7. The app uses a com.google.inject.persist.jpa.JpaPersistModule and
a com.google.inject.persist.PersistFilter
For some
Hi,
I think the issue will be in the MyRunnable class.
You create the MyRunnable instance in the http worker thread, if you simply
inject an EntityManager there it'll be the one bound to the current thread
(the http worker). After submitting it to a different thread you
essentially leak the
First of all: guice-persist has some known bugs and they haven't been fixed for
a long time. It looks like the extension is no longer maintained. Have a look
into
http://onami.apache.org/persist/
It is concepionally build on guice persist and migrating existing code should
be very easy.
Hi Laszio,
Thank you for your answer.
I think you pinpointed the problem, and I'm a step forward in resolving it.
Here is the MyRunnable implementation, it already relies on two providers for
EntityManager and UnitOfWork.
But now my question is : how to make sure that the
The persist framework takes care that every thread has its own entity manager.
So you don't need to do this.
Calling unitOfWork.end() will close the entity manager for you. So also no need
to do this manually.
The unitOfWork is a singleton. So you can inject it directly and don't need to
use
Hi Stephan,
I followed your advices, and it seems that I don't have the error when I inject
a UnitOfWork instead of a ProviderUnitOfWork.
As far as I understand it, if a MyRunnable gets executed by the ExecutorService
before the end of the MyServletWorker, then it receives a copy of the
Almost.
UnitOfWork is in the singleton scope. This means there will exist exactly one
instance for the entire injector. So it does not matter if you inject it
directly or retrieve it from a provider. You will always recieve the very same
(and only) instance.
The EntityManager on the other