[
https://issues.apache.org/jira/browse/ONAMI-117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14945041#comment-14945041
]
Nicolas MARQUES commented on ONAMI-117:
---------------------------------------
To answer the initial question, here my entire code with 2 privates modules. Is
there a limitation to have private modules ? My example is very simple, and
aims to tests JTA connections with guice/onami-persists and transactions
manager. But, in production private modules match application components. Each
components can brings XA connections (and of course persists units). That's why
i want to test it.
In only one module, it's works (even if @Transaction(type=REQUIRES_NEW) would
be perfect to open a sub transaction...)
My following code :
{code}
public static void main(String[] args) throws NamingException
{
// Initialize BitronixTransactionManager / Do connections to
datasources
JTATransactionManagerServiceImpl transactionManager = new
JTATransactionManagerServiceImpl();
transactionManager.start();
try
{
PrivateModule module1 = new PrivateModule()
{
@Override
protected void configure()
{
install(new PersistenceModule()
{
@Override
protected void
configurePersistence()
{
System.out.println(">>
--- Module 1--------------------------------------");
EntityManagerFactory
emf = Persistence.createEntityManagerFactory("datasource1");
bindContainerManagedPersistenceUnit(emf).annotatedWith(Datasource1.class)
.useGlobalTransactionWithJndiName(JTATransactionManagerServiceImpl.JNDI_USER_TRANSACTION);
}
});
}
};
PrivateModule module2 = new PrivateModule()
{
@Override
protected void configure()
{
install(new PersistenceModule()
{
@Override
protected void
configurePersistence()
{
System.out.println(">>
--- Module 2--------------------------------------");
EntityManagerFactory
emf = Persistence.createEntityManagerFactory("datasource2");
bindContainerManagedPersistenceUnit(emf).annotatedWith(Datasource2.class)
.useGlobalTransactionWithJndiName(JTATransactionManagerServiceImpl.JNDI_USER_TRANSACTION);
}
});
}
};
final Injector injector = Guice.createInjector(module1,
module2);
AllPersistenceServices persistenceService =
injector.getInstance(AllPersistenceServices.class);
try
{
persistenceService.startAllStoppedPersistenceServices();
injector.getInstance(SuperTransactional.class).testIt(); // Call different DAO
and execute queries to test database connections
}
finally
{
persistenceService.stopAllPersistenceServices();
}
}
finally
{
transactionManager.stop();
}
}
{code}
It throws an Exception
{code}
1) Unable to create binding for
org.apache.onami.persist.AllPersistenceServices. It was already configured on
one or more child injectors or private modules
bound at
org.apache.onami.persist.PersistenceModule.configurePersistenceUnits(PersistenceModule.java:80)
If it was in a PrivateModule, did you forget to expose the binding?
while locating org.apache.onami.persist.AllPersistenceServices
1 error
at
com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1004)
at
com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:961)
at
com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)
{code}
> Multiple JTA datasource in standalone application
> -------------------------------------------------
>
> Key: ONAMI-117
> URL: https://issues.apache.org/jira/browse/ONAMI-117
> Project: Apache Onami
> Issue Type: Question
> Components: persist
> Affects Versions: persist-1.0.1
> Reporter: Nicolas MARQUES
>
> I use multiple datasource in a JTA environnement (with
> BitronixTransactionManager).
> To do that, i create a privateModule for each datasource environment with a
> persistentModule installed.
> I followed the given example :
> {panel} bindContainerManagedPersistenceUnit(entityManagerFactory)
> .annotatedWith(clazz)
> .useGlobalTransactionWithJndiName(JTATransactionManagerServiceImpl.JNDI_USER_TRANSACTION);
> {panel}
> In my main class, the problem is that i cannot access to the
> PersistentService since there is not an only one neither to
> AllPersistenceServices class.
> {panel}
> Exception in thread "main" com.google.inject.ConfigurationException: Guice
> configuration errors:
> 1) Unable to create binding for
> org.apache.onami.persist.AllPersistenceServices. It was already configured on
> one or more child injectors or private modules
> bound at
> org.apache.onami.persist.PersistenceModule.configurePersistenceUnits(PersistenceModule.java:80)
> If it was in a PrivateModule, did you forget to expose the binding?
> while locating org.apache.onami.persist.AllPersistenceServices
> 1 error
> at
> com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1004)
> at
> com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:961)
> at
> com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)
> at nico.jta.JPAClient.main(JPAClient.java:49)
> {panel}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)