Kohei Nozaki
2016-06-13 10:11:42 UTC
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.
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/84ba2ff6-eb3e-42c0-96d1-b48e8075659e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/84ba2ff6-eb3e-42c0-96d1-b48e8075659e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.