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
Hibernate 同时映射三个数据库_Hibernate_Jpa - Fatal编程技术网

Hibernate 同时映射三个数据库

Hibernate 同时映射三个数据库,hibernate,jpa,Hibernate,Jpa,我必须使用Hibernate/JPA在我的项目(Web应用程序)上映射三个数据库,所以我的问题是如何配置persistence.xml以支持这三个连接 这是我的文件: persistence.xml <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org

我必须使用Hibernate/JPA在我的项目(Web应用程序)上映射三个数据库,所以我的问题是如何配置persistence.xml以支持这三个连接 这是我的文件: persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="JiraMapPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>DTOKpi.AssociationKpiProfil</class>  //from  database1
<class>DTOKpi.Kpi</class>                  //database1
<class>DTOKpi.ProfilUser</class>          //  database1
<class>DTOJIRA.Resolution</class>         //  database2
<class>DTOJIRA.Project</class>           //  database2
<class>DTOJIRA.Issuestatus</class>
<class>DTOJIRA.Jiraissue</class>
<class>DTOJIRA.Priority</class>
<class>DTOJIRA.Component</class>
<class>DTOJIRA.Issuetype</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jiradb"/>
  <property name="javax.persistence.jdbc.password" value="root"/>
  <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.user" value="root"/>
</properties>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD  3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jiradb</property>
<property name="hibernate.connection.username">root</property>
<mapping resource="DTOTest/issuestatus.hbm.xml"/>
<mapping resource="hibernate.hbm.xml"/>
</session-factory>
</hibernate-configuration>

org.eclipse.persistence.jpa.PersistenceProvider
来自数据库1的DTOKpi.AssociationKpiProfil//
DTOKpi.Kpi//数据库1
DTOKpi.ProfilUser//数据库1
DTOJIRA.分辨率//数据库2
项目//数据库2
德托吉拉·伊塞斯塔斯
德托吉拉,吉莱苏
德托吉拉,优先权
DTOJIRA.组件
DTOJIRA.Issuetype
假的

My hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="JiraMapPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>DTOKpi.AssociationKpiProfil</class>  //from  database1
<class>DTOKpi.Kpi</class>                  //database1
<class>DTOKpi.ProfilUser</class>          //  database1
<class>DTOJIRA.Resolution</class>         //  database2
<class>DTOJIRA.Project</class>           //  database2
<class>DTOJIRA.Issuestatus</class>
<class>DTOJIRA.Jiraissue</class>
<class>DTOJIRA.Priority</class>
<class>DTOJIRA.Component</class>
<class>DTOJIRA.Issuetype</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jiradb"/>
  <property name="javax.persistence.jdbc.password" value="root"/>
  <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.user" value="root"/>
</properties>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD  3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jiradb</property>
<property name="hibernate.connection.username">root</property>
<mapping resource="DTOTest/issuestatus.hbm.xml"/>
<mapping resource="hibernate.hbm.xml"/>
</session-factory>
</hibernate-configuration>

org.hibernate.dialogue.mysqldialogue
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/jiradb
根

我发现此链接很有用:但我无法理解第二步

如果您的三个数据库是相同的,我想它会工作,但如果不是,我认为您应该为每个数据库创建一个映射文件。

您好,我找到了解决方案,我为我的第二个数据库添加了另一个:)