3 Replies Latest reply on Nov 11, 2008 1:12 PM by Peter Johnson

    Seam with Multiple Datasouces

    Mita Bhushan Newbie

      I am tring to use multiple datasources in a seam project

      xx-ds.xml is


      <datasources>
      
       <local-tx-datasource>
       <jndi-name>hrtrackerDatasource</jndi-name>
       <connection-url>jdbc:mysql://xx:3306/hrtracker</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>xx</user-name>
       <password>xx</password>
       </local-tx-datasource>
      
      
       <local-tx-datasource>
       <jndi-name>employeeDatasource</jndi-name>
       <connection-url>jdbc:as400://xxx/medlib/mnuusr</connection-url>
       <driver-class>com.ibm.as400.access.AS400JDBCDriver</driver-class>
       <user-name>xx</user-name>
       <password>xx</password>
       </local-tx-datasource>
      


      persistence-dev.xml
       <persistence-unit name="hrtracker">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/hrtrackerDatasource</jta-data-source>
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
       <property name="hibernate.hbm2ddl.auto" value="validate"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="hibernate.format_sql" value="true"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/hrtrackerEntityManagerFactory"/>
       <property name="hibernate.default_catalog" value="hrtracker"/>
       </properties>
       </persistence-unit>
      
       <persistence-unit name="employee" >
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/employeeDatasource</jta-data-source>
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" />
       <property name="hibernate.hbm2ddl.auto" value="validate"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="hibernate.format_sql" value="true"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/employeeEntityManagerFactory"/>
       <property name="hibernate.default_catalog" value="xxxx"/>
       <property name="hibernate.default_schema" value="PRODDTA"/>
       </properties>
       </persistence-unit>
      


      components.xml
      <persistence:managed-persistence-context name="entityManager"
       auto-create="true"
       persistence-unit-jndi-name="java:/hrtrackerEntityManagerFactory"/>
      
       <persistence:managed-persistence-context name="employeeManager"
       auto-create="true"
       persistence-unit-jndi-name="java:/employeeEntityManagerFactory"/>
      
      


      I used following pattern for class files
      EmployeeList.java
      package com.hrtracker.session;
      
      import javax.persistence.EntityManager;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.framework.EntityQuery;
      
      import com.hrtracker.entity.*;
      
      @Name("employeeList")
      public class EmployeeList extends EntityQuery {
       .................
       @Override
       protected String getPersistenceContextName() {
       return "employeeManager";
       }
      }
      



      Employee.java
      package com.med.stryker.hrtracker.entity;
      ...
      
      @Entity
      @Table(name="F0101")
      public class Employee implements java.io.Serializable
      {
       @In
       EntityManager employeeManager;
      
       ...............
      }
      


      I redeployed using restart seam
      hibernate.connection.password=xxxx
      workspace.home=C\:/ProServers/Workspace
      model.package=com.hrtracker.entity
      hibernate.default_catalog=hrtracker
      driver.jar=C\:\\ProServers\\drivers\\mysql-connector-java-5.0.4-bin.jar
      action.package=com.hrtracker.session
      test.package=com.hrtracker.test
      database.type=mysql
      richfaces.skin=classic
      hibernate.default_schema.null=
      database.drop=n
      project.name=hrtracker
      hibernate.connection.username=xxxxx
      hibernate.connection.driver_class=com.mysql.jdbc.Driver
      hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
      project.type=ear
      icefaces.home=
      database.exists=y
      jboss.home=C\:/ProServers/jboss-4.2.2.GA
      hibernate.dialect=org.hibernate.dialect.MySQLDialect
      hibernate.connection.url=jdbc\:mysql\://xxxx\:3306/hrtracker
      icefaces=n
      

      The error I am getting is
      ObjectName: persistence.units:ear=hrtracker.ear,unitName=employee
       State: FAILED
       Reason: javax.persistence.PersistenceException: org.hibernate.HibernateException: Missing table: audit_military
       I Depend On:
       jboss.jca:service=DataSourceBinding,name=employeeDatasource
      
      ObjectName: persistence.units:ear=hrtracker.ear,unitName=hrtracker
       State: FAILED
       Reason: javax.persistence.PersistenceException: org.hibernate.HibernateException: Missing table: F0101
       I Depend On:
       jboss.jca:service=DataSourceBinding,name=hrtrackerDatasource

      Stacktrace is
      com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/home.xhtml]
      java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:/hrtrackerEntityManagerFactory
       at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:247)
       at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:79)
       at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:108)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
       at org.jboss.seam.Component.callComponentMethod(Component.java:2082)
       at org.jboss.seam.Component.unwrap(Component.java:2108)
       at org.jboss.seam.Component.getInstance(Component.java:1887)
       at org.jboss.seam.Component.getInstance(Component.java:1840)
       at org.jboss.seam.Component.getInstance(Component.java:1834)
       at org.jboss.seam.framework.Controller.getComponentInstance(Controller.java:263)
       at org.jboss.seam.framework.PersistenceController.getPersistenceContext(PersistenceController.java:20)
       at org.jboss.seam.framework.EntityQuery.getEntityManager(EntityQuery.java:153)
       at org.jboss.seam.framework.EntityQuery.validate(EntityQuery.java:37)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
       at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
       at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
       at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
       at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
       at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)

      Please help!