|
Its possible but its way more complicated. In Fact the Provider<EntityManager>, UnitOfWork and PersistService are all implemented in the single class JpaPersistService. And the JpaPersistService has a static inner class which is the Provider<EntityManagerFactory> which it uses directly and not over injection. This implementation couples all the above interfaces so tightly that I don't see a way to get in between them. This means you would have to rewrite all of them. It is not that hard to do. My opinion is that you would need two classes: - one which implements PersistService and Provider<EntityManagerFactory> - one which implements UnitOfWork and Provider<EntityManager> Most of the code can be copied from the JpaPersistService. And finally you would have to write you own XxxPersistModule which binds the above classes. Since creating an EntityManagerFactory is expensive it might be worth storing the created ones in a map for later reuse. On 09/27/2012 10:01 AM, Martin Schayna
wrote:
Thanks a lot. In my case I have to parametrize creation of EntityManagerFactory, not EntityManager, because each request may work with different database. Persistence unit defined in persistence.xml is the same one, but properties like hibernate.connection.url are passed to Persistence.createEntityManagerFactory("persistence-unit", myProperties). -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. |
- guice-persist and JPA: working with multiple EntityManager... Martin Schayna
- Re: guice-persist and JPA: working with multiple Enti... Stephan Classen
- Re: guice-persist and JPA: working with multiple ... Martin Schayna
- Re: guice-persist and JPA: working with multi... Stephan Classen
- Re: guice-persist and JPA: working with multiple Enti... Daniel Bimschas
- Re: guice-persist and JPA: working with multiple ... Stephan Classen
- Re: guice-persist and JPA: working with multi... Laszlo Ferenczi
