0 Replies Latest reply on Jun 30, 2015 5:47 PM by Shr Pathi

    How to add 2 DBs in persistence.xml in EAP 6.3

    Shr Pathi Newbie

      We are referring two different database connection ie 'NBDX' & 'NBPTS' in a project called MyProject. We have migrated Jboss from 5 to EAP 6 .3. I have specified two different perisistence.xml file.

       

      First one in meta-inf/persistence.xml

       

      <persistence xmlns="http://java.sun.com/xml/ns/persistence"

      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"

      version="2.0">

      <persistence-unit name="nbpts">

        <class>com.myproject.persistence.BookletCode</class>

        <class>com.myproject.persistence.ClipData</class>

        <class>com.myproject.persistence.CronJob</class>

        <class>com.myproject.persistence.ExerciseCodePK</class>

        <class>com.myproject.persistence.ExerciseCode</class>

        <class>com.myproject.persistence.ExportFile</class>

        <class>com.myproject.persistence.Hold</class>

        <class>com.myproject.persistence.InputFile</class>

        <class>com.myproject.persistence.InputRecord</class>

        <class>com.myproject.persistence.MessageLog</class>

        <class>com.myproject.persistence.NbricCodePK</class>

        <class>com.myproject.persistence.NbricCode</class>

        <class>com.myproject.persistence.OEMappingPK</class>

        <class>com.myproject.persistence.OEMapping</class>

        <class>com.myproject.persistence.OERecord</class>

        <class>com.myproject.persistence.Parameters</class>

        <class>com.myproject.persistence.PostEditData</class>

        <class>com.myproject.persistence.PreidRecord</class>

        <class>com.myproject.persistence.ProcessLog</class>

        <class>com.myproject.persistence.Response</class>

        <class>com.myproject.persistence.Score</class>

        <class>com.myproject.persistence.SetupFilePK</class>

        <class>com.myproject.persistence.SetupFile</class>

        <class>com.myproject.persistence.SftpConfig</class>

        <class>com.myproject.persistence.TestMap</class>

        <class>com.myproject.persistence.User</class>

        <class>com.myproject.persistence.DataPrep</class>

        <properties>

         <property name="hibernate.archive.autodetection" value="class" />

         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />

         

         <property name="hibernate.hbm2ddl.auto" value="validate" />

          

         <property name="hibernate.show_sql" value="false" />

         <property name="hibernate.format_sql" value="false" />

         <property name="hibernate.use_sql_comments" value="false" />

         <property name="hibernate.id.new_generator_mappings" value="false" />

         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />

         <property name="hibernate.cache.use_second_level_cache" value="false"/>

        </properties>

      </persistence-unit>

      <persistence-unit name="nbdx">

        <properties>

         <property name="hibernate.archive.autodetection" value="class" />

         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />  

         <property name="hibernate.show_sql" value="false" />

         <property name="hibernate.format_sql" value="false" />

         <property name="hibernate.use_sql_comments" value="false" />

         <property name="hibernate.id.new_generator_mappings" value="false" />

         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />

         <property name="hibernate.cache.use_second_level_cache" value="false"/>

        </properties>

      </persistence-unit>

      </persistence>

       

       

      Other one is war/meta-inf/persistence.xml

      <persistence xmlns="http://java.sun.com/xml/ns/persistence"

      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"

      version="2.0">

      <persistence-unit name="nbpts">

        <jta-data-source>java:/nbptsDS</jta-data-source>

        <class>com.myproject.persistence.BookletCode</class>

        <class>com.myproject.persistence.ClipData</class>

        <class>com.myproject.persistence.CronJob</class>

        <class>com.myproject.persistence.ExerciseCodePK</class>

        <class>com.myproject.persistence.ExerciseCode</class>

        <class>com.myproject.persistence.ExportFile</class>

        <class>com.myproject.persistence.Hold</class>

        <class>com.myproject.persistence.InputFile</class>

        <class>com.myproject.persistence.InputRecord</class>

        <class>com.myproject.persistence.MessageLog</class>

        <class>com.myproject.persistence.NbricCodePK</class>

        <class>com.myproject.persistence.NbricCode</class>

        <class>com.myproject.persistence.OEMappingPK</class>

        <class>com.myproject.persistence.OEMapping</class>

        <class>com.myproject.persistence.OERecord</class>

        <class>com.myproject.persistence.Parameters</class>

        <class>com.myproject.persistence.PostEditData</class>

        <class>com.myproject.persistence.PreidRecord</class>

        <class>com.myproject.persistence.ProcessLog</class>

        <class>com.myproject.persistence.Response</class>

        <class>com.myproject.persistence.Score</class>

        <class>com.myproject.persistence.SetupFilePK</class>

        <class>com.myproject.persistence.SetupFile</class>

        <class>com.myproject.persistence.SftpConfig</class>

        <class>com.myproject.persistence.TestMap</class>

        <class>com.myproject.persistence.User</class>

        <class>com.myproject.persistence.DataPrep</class>

        <properties>

         <property name="hibernate.archive.autodetection" value="class" />

         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />

         

         <property name="hibernate.hbm2ddl.auto" value="validate" />

          

         <property name="hibernate.show_sql" value="false" />

         <property name="hibernate.format_sql" value="false" />

         <property name="hibernate.use_sql_comments" value="false" />

         <property name="hibernate.id.new_generator_mappings" value="false" />

         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />

         <property name="hibernate.cache.use_second_level_cache" value="false"/>

        </properties>

      </persistence-unit>

      <persistence-unit name="nbdx">

        <jta-data-source>java:/nbdxDS</jta-data-source>

        <properties>

         <property name="hibernate.archive.autodetection" value="class" />

         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />  

         <property name="hibernate.show_sql" value="false" />

         <property name="hibernate.format_sql" value="false" />

         <property name="hibernate.use_sql_comments" value="false" />

         <property name="hibernate.id.new_generator_mappings" value="false" />

         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />

         <property name="hibernate.cache.use_second_level_cache" value="false"/>

        </properties>

      </persistence-unit>

      </persistence>

       

      I am referring datasource. For nbdx it is nbdxDS and nbpts it is nbptsDS

      Both the DB connection has same table name called EXERCISE_CODES. So it is getting confused and picking up other table and is not deploying the war file.

      Here is the error

       


      > 16:13:47,277 INFO  [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 48) HHH000261: Table found: NBDX_DEV.EXERCISE_CODES

      > 16:13:47,277 INFO  [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 48) HHH000037: Columns: [ex3, ex4, ex5, ex6, ex2, code_name, ex1, cert_version]

      > 16:13:47,278 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 48) MSC000001: Failed to start service jboss.persistenceunit."nbpts.war#nbpts": org.jboss.msc.service.StartException in service jboss.persistenceunit."nbpts.war#nbpts": javax.persistence.PersistenceException: [PersistenceUnit: nbpts] Unable to build EntityManagerFactory
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:103)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_65]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_65]
      at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_65]
      at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final-redhat-1.jar:2.1.1.Final-redhat-1]

      > Caused by: javax.persistence.PersistenceException: [PersistenceUnit: nbpts] Unable to build EntityManagerFactory
      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)
      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
      at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:76)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:200)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$600(PersistenceUnitServiceImpl.java:57)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:99)
      ... 4 more

      > Caused by: org.hibernate.HibernateException: Missing column: CYCLE in NBDX_DEV.EXERCISE_CODES
      at org.hibernate.mapping.Table.validateColumns(Table.java:366)
      at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1305)
      at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155)
      at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:512)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1797)
      at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
      ... 9 more

      > JBAS014777:   Services which failed to start:      service jboss.persistenceunit."nbpts.war#nbpts": org.jboss.msc.service.StartException in service jboss.persistenceunit."nbpts.war#nbpts": javax.persistence.PersistenceException: [PersistenceUnit: nbpts] Unable to build EntityManagerFactory

      > 16:13:47,733 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management

      > 16:13:47,733 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990

      > 16:13:47,733 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: JBoss EAP 6.3.0.GA (AS 7.4.0.Final-redhat-19) started (with errors) in 10702ms - Started 219 of 279 services (20 services failed or missing dependencies, 59 services are lazy, passive or on-demand)

       

      could you please help me out?