Hi Stephan,

Thanks for the info. eventually I created two annotated bindings for JPA 
classes. also I have blogged about it: 
http://www.nailedtothex.org/roller/kyle/entry/managing-multiple-jpa-persistence-units

Thanks,
Kohei

2016年6月13日月曜日 19時23分26秒 UTC+9 scl:
>
> This is not possible. You need to define an notation for both 
> entitymanagers.
>
> Also have a look at onami-persist for enhanced multi pu support
>
> Am 13. Juni 2016 12:11:42 MESZ, schrieb Kohei Nozaki <[email protected] 
> <javascript:>>:
>>
>> Hello,
>>
>> I want to create two EntityManager binding with guice-persist as follows:
>>
>> 1. Without any annotation
>> 2. With an annotation (say, @SlaveDatabase)
>>
>> So, I have created following module:
>>
>> public class MyModule extends AbstractModule {
>>
>>     @Override
>>     protected void configure() {
>>         install(new MasterPrivateModule());
>>         install(new SlavePrivateModule());
>>     }
>>
>>     private static class MasterPrivateModule extends PrivateModule {
>>         @Override
>>         protected void configure() {
>>             install(new JpaPersistModule("masterPU"));
>>
>>             expose(EntityManager.class);
>>         }
>>     }
>>
>>     private static class SlavePrivateModule extends PrivateModule {
>>         @Override
>>         protected void configure() {
>>             install(new JpaPersistModule("slavePU"));
>>
>>             final Provider<EntityManager> entityManagerProvider = 
>> binder().getProvider(EntityManager.class);
>>             
>> bind(EntityManager.class).annotatedWith(SlaveDatabase.class).toProvider(entityManagerProvider);
>>             
>> expose(EntityManager.class).annotatedWith(SlaveDatabase.class);
>>         }
>>     }
>> }
>>
>> But it doesn't work. Guice produces following error:
>>
>> com.google.inject.CreationException: Unable to create injector, see the 
>> following errors:
>>
>> 1) A binding to javax.persistence.EntityManager was already configured at 
>> mypkg.MyModule$MasterPrivateModule.configure(MyModule.java:25) (via 
>> modules: mypkg.MyModule -> mypkg.MyModule$MasterPrivateModule).
>>   at 
>> com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:69)
>>  
>> (via modules: mypkg.MyModule -> mypkg.MyModule$SlavePrivateModule -> 
>> com.google.inject.persist.jpa.JpaPersistModule)
>> ...
>>
>> How do I write a module to achieve this requirement?
>>
>> I have pushed a reproducer (testcase) and entire project to GitHub:
>>
>> * Entire project: 
>> https://github.com/lbtc-xxx/guice-persist-multiple-pu/tree/simplified
>> * Reproducer (testcase): 
>>
>> https://github.com/lbtc-xxx/guice-persist-multiple-pu/blob/simplified/src/test/java/mypkg/MyModuleTest.java
>>
>> Thanks.
>>
>>

-- 
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 https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/415b47db-b341-439b-9ebb-32d946300b80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to