1. 程式人生 > >EJB 配置多個數據源

EJB 配置多個數據源

name XML cti kong 添加 local ima 不能 transacti

1.修改jboss-6.simple\server\default\deploy\transaction-jboss-beans.xml

配置文件

<bean name="CoreEnvironmentBean" class="com.arjuna.ats.arjuna.common.CoreEnvironmentBean">

中增加

<property name="allowMultipleLastResources">true</property>

2.添加xx_ds.xml配置文件

比如有兩個數據庫sqlserver和oracle

添加mssql-ds.xml

技術分享

添加oracle-ds.xml

技術分享

如果有兩個sqlserver或者oracle,在一個配置文件中添加兩個

<local-tx-datasource>

</local-tx-datasource>

3.配置persistence.xml

技術分享

其中

<exclude-unlisted-classes>true</exclude-unlisted-classes>不能少,<class>com.railway.entity.AssetsEntity</class>

<class>com.railway.entity.FaultEntity</class>為你對應數據庫的實體類。

4.調用Datasource

@PersistenceContext(unitName="jifangjiankong") EntityManager em;

EJB 配置多個數據源