且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

可以为多个数据源配置persistence.xml吗?

更新时间:2022-11-03 15:39:54

是的,你可以在持久性中配置两个数据源。 XML。你只需要两个独立的元素。

Yeah, you can have two datasources configured in a persistence.xml. You would just need two separate elements.

<persistence>
   <persistence-unit name="datasourceOne">
       <jta-data-source>java:/DefaultDS</jta-data-source>
       <jar-file>../MyApp.jar</jar-file>
       <class>org.acme.Employee</class>
       <class>org.acme.Person</class>
       <class>org.acme.Address</class>
       <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       </properties>
   </persistence-unit>

   <persistence-unit name="datasourceTwo">
     <!-- some configuration -->
  </persistence-unit>
</persistence>