如何在EAP 6.3中的persistence.xml中添加2个数据库

时间:2015-06-30 21:28:01

标签: java hibernate jboss

我们指的是两个不同的数据库连接,即' NBDX' &安培; ' NBPTS'在一个名为MyProject的项目中。我们已将Jboss从5迁移到EAP 6 .3。我已经指定了两个不同的perisistence.xml文件。

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>

另一个是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>

我指的是数据源。对于nbdx,它是nbdxDS,nbpts是nbptsDS 数据库连接都具有相同的表名称EXERCISE_CODES。所以它变得困惑并且拿起其他表并且没有部署war文件。

这是错误

  

16:13:47,277 INFO [org.hibernate.tool.hbm2ddl.TableMetadata](ServerService线程池 - 48)HHH000261:找到的表:NBDX_DEV.EXERCISE_CODES

     

16:13:47,277 INFO [org.hibernate.tool.hbm2ddl.TableMetadata](ServerService线程池 - 48)HHH000037:列:[ex3,ex4,ex5,ex6,ex2,code_name,ex1,cert_version] < / p>      

16:13:47,278 ERROR [org.jboss.msc.service.fail](ServerService线程池 - 48)MSC000001:无法启动服务jboss.persistenceunit。&#34; nbpts.war#nbpts&#34; :服务jboss.persistenceunit中的org.jboss.msc.service.StartException。&#34; nbpts.war #nbpts&#34;:javax.persistence.PersistenceException:[PersistenceUnit:nbpts]无法构建EntityManagerFactory       在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]       在java.lang.Thread.run(Thread.java:745)[rt.jar:1.7.0_65]       在org.jboss.threads.JBossThread.run(JBossThread.java:122)[jboss-threads-2.1.1.Final-redhat-1.jar:2.1.1.Final-redhat-1]

     

引起:javax.persistence.PersistenceException:[PersistenceUnit:nbpts]无法构建EntityManagerFactory       在org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)       在org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)       在org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:76)       在org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:200)       在org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access $ 600(PersistenceUnitServiceImpl.java:57)       在org.jboss.as.jpa.service.PersistenceUnitServiceImpl $ 1.run(PersistenceUnitServiceImpl.java:99)       ......还有4个

     

引起:org.hibernate.HibernateException:缺少列:NBDX_DEV.EXERCISE_CODES中的CYCLE       在org.hibernate.mapping.Table.validateColumns(Table.java:366)       在org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1305)       在org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155)       在org.hibernate.internal.SessionFactoryImpl。(SessionFactoryImpl.java:512)       在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1797)       在org.hibernate.ejb.EntityManagerFactoryImpl。(EntityManagerFactoryImpl.java:96)       在org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)       ... 9更多

     

JBAS014777:无法启动的服务:服务jboss.persistenceunit。&#34; nbpts.war#nbpts&#34;:org.jboss.msc.service.StartException in service jboss.persistenceunit。&#34; nbpts。 war#nbpts&#34;:javax.persistence.PersistenceException:[PersistenceUnit:nbpts]无法构建EntityManagerFactory

     

16:13:47,733 INFO [org.jboss.as](控制器启动线程)JBAS015961:Http管理界面监听http://127.0.0.1:9990/management

     

16:13:47,733 INFO [org.jboss.as](控制器启动线程)JBAS015951:管理控制台监听http://127.0.0.1:9990

     

16:13:47,733 ERROR [org.jboss.as](控制器启动线程)JBAS015875:JBoss EAP 6.3.0.GA(AS 7.4.0.Final-redhat-19)在10702ms内启动(有错误) - 279个服务中的219个(20个服务失败或缺少依赖,59个服务是懒惰,被动或按需)

你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

我取消了它。由于某些原因,EAP没有获取正确的架构名称,因此必须在属性名称中设置架构名称hibernate.default_schema <property name="hibernate.default_schema" value="NBPTS" />