*>@Inject*
*>private EntityManager em;*
Don't know how to answer your question, but here you should inject
Provider<EntityManager> instead of EntityManager. The reason is that service
classes are stored like singletons, and hence you should inject a provider
as explained here
http://code.google.com/p/google-guice/wiki/JPA#Using_the_inside_transactions

On Fri, Sep 23, 2011 at 12:12 PM, koma <k...@koma.be> wrote:

> Hi
>
> Starting up a new project using *RF* and *guice-persist* on the
> server-side to start JPA and provide transaction management.
>
> I have a couple of tests going to inject the EntityManager into the
> services via the ServiceLocator :
>
> public class *ApplicationServiceLocator* implements ServiceLocator {
>
> Injector injector = null;
>
> public ApplicationServiceLocator() {
>
> injector = Guice.createInjector(new JpaPersistModule("Test"));
>
> injector.getInstance(ApplicationInitializer.class);
>
> }
>
> @Override
>
> public Object getInstance(Class<?> clazz) {
>
> *return injector.getInstance(clazz);*
>
> }
>
> }
>
>
> This makes sure that is EntityManager injected into the service layers :
>
> public class *WorkerServiceImpl* {
>
> *@Inject*
> *private EntityManager em;*
>
> @Transactional
> public List<Contract> getContracts(User user) {
> *// I can us EntityManager now !! Injected because created this 
> WorkerServiceImpl
> was created via injector.getInstance
> * }
>
>
> My question : what would be a good approach to inject the EntityManager
> into an entity class when implementing a service in an entity class ?
> What hooks do I have available to do so ?
>
>
> thx
>
> Koen
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/CDzbDvioxCAJ.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>



-- 
Magno Machado Paulo
http://blog.magnomachado.com.br
http://code.google.com/p/emballo/

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to