说明:{JBOSS_HOME}代表JBOSS程序目录
<1>.拷贝两个数据源(mssql和mysql)
{JBOSS_HOME}/doc/examples/jca/mssql-ds.xml 到 {JBOSS_HOME}/server/default/deploy/mssql-ds.xml
{JBOSS_HOME}/doc/examples/jca/mysql-ds.xml 到{JBOSS_HOME}/server/default/deploy/mysql-ds.xml
<?xml version="1.0" encoding="UTF-8" ?>
<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_1_0.xsd" version="1.0">
<persistence-unit name="itcast" transaction-type="JTA">
<jta-data-source>java:MySqlDS</jta-data-source>
<class>com.lixing.bean.Person</class> <!-- 以下两项必须定义-->
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
<persistence-unit name="microsoft_sql" transaction-type="JTA">
<jta-data-source>java:microsoft_datasource</jta-data-source>
<class>com.lixing.bean.User</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
<3>定义两个Entity Bean,并分别映射到不同的数据源(Person映射到:mysql/jbossdb数据库下 User映射到:mssql/test数据库下)
--------------------------------------------------------------------Person---------------------------------------------------------------------------------
package com.lixing.entity;
@Entity
@Table(name="t_person",catalog="jbossdb")
public class Person{
//...
}
---------------------------------------------------------------------User.class-----------------------------------------------------------------------------
package com.lixing.entity;
@Entity
@Table(name="t_user",schema="dbo",catalog="test")
public class User{
//......
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------
两处唯一不同的地方即是:Person映射到jbossdb数据库时(mysql),没有定义schema="dbo",而User映射到test数据库时(mssql),却定义了schema="dbo"