Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JPA-多个持久性单元_Jpa_Persistence_Openjpa_Jta_Persistence.xml - Fatal编程技术网

JPA-多个持久性单元

JPA-多个持久性单元,jpa,persistence,openjpa,jta,persistence.xml,Jpa,Persistence,Openjpa,Jta,Persistence.xml,我正在使用JPA,我正在连接多个数据库。下面是persistence.xml- <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> <persistence-unit name="myRead" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.jpa.Hibernate

我正在使用JPA,我正在连接多个数据库。下面是persistence.xml-

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

    <persistence-unit name="myRead" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
            <property name="hibernate.show_sql" value="true" />
        </properties>
    </persistence-unit>

    <persistence-unit name="myWrite" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <class>com.test.model.Person</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
            <property name="hibernate.show_sql" value="true" />
        </properties>
    </persistence-unit>

</persistence>

org.hibernate.jpa.HibernatePersistenceProvider
org.hibernate.jpa.HibernatePersistenceProvider
com.test.model.Person

当Spring上下文加载时,它试图从
myRead
持久化单元中查找
Person
表。Spring根本无法识别第二个持久性单元。有人可以帮忙吗。

如果您不想在特定的持久化单元中使用某些类,请排除未列出的类问题在于Spring上下文根本没有加载第二个持久化单元。它正在尝试从配置了不同数据库的“myRead”持久化单元中查找“Person”表。它以“找不到表”的形式抛出异常。为什么仅仅因为持久性单元在persistence.xml中,它就应该“加载”持久性单元???除非您共享引用这些持久性单元的代码,否则在这里就没有意义