[ 
https://issues.apache.org/jira/browse/ONAMI-117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14944976#comment-14944976
 ] 

Nicolas MARQUES edited comment on ONAMI-117 at 10/6/15 1:44 PM:
----------------------------------------------------------------

Ok, my bad. It's my understanding.

My code :
{code}EntityManagerFactory emf = 
Persistence.createEntityManagerFactory("datasource1");

Class<? extends Annotation> clazz = Names.named("datasource1").annotationType();

bindContainerManagedPersistenceUnit(emf)
.annotatedWith(clazz)
.useGlobalTransactionWithJndiName(JTATransactionManagerServiceImpl.JNDI_USER_TRANSACTION);
{code}

The problem is that i haven't create a annotation for my persistUnit. I used a 
@Named("datasource") instead. It seems that a special class annotations has to 
be written for the persist unit and used both in bindingds and DAO.

My DAO :
{panel}
public class DatasourceDao
{

        private final EntityManagerProvider entityManagerProvider;

        @Inject
        public DatasourceDao(@Named("datasource1") EntityManagerProvider 
entityManagerProvider){
                this.entityManagerProvider = entityManagerProvider;
        ...
{panel}

Am i wrong ? 

By the way, is there a way to make my DAO generic (all i need is a entity 
manager, no matter of persist unit) ? like to build a Provider of 
EntityManagerProvider to inject depending on persist unit name ?
Thanks !


was (Author: nicolas marques):
Ok, my bad. It's my understanding.

My code :
{panel}EntityManagerFactory emf = 
Persistence.createEntityManagerFactory("datasource1");

Class<? extends Annotation> clazz = Names.named("datasource1").annotationType();

bindContainerManagedPersistenceUnit(emf)
.annotatedWith(clazz)
.useGlobalTransactionWithJndiName(JTATransactionManagerServiceImpl.JNDI_USER_TRANSACTION);
{panel}

The problem is that i haven't create a annotation for my persistUnit. I used a 
@Named("datasource") instead. It seems that a special class annotations has to 
be written for the persist unit and used both in bindingds and DAO.

My DAO :
{panel}
public class DatasourceDao
{

        private final EntityManagerProvider entityManagerProvider;

        @Inject
        public DatasourceDao(@Named("datasource1") EntityManagerProvider 
entityManagerProvider){
                this.entityManagerProvider = entityManagerProvider;
        ...
{panel}

Am i wrong ? 

By the way, is there a way to make my DAO generic (all i need is a entity 
manager, no matter of persist unit) ? like to build a Provider of 
EntityManagerProvider to inject depending on persist unit name ?
Thanks !

> 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)

Reply via email to