在EJB开发中碰到一个问题,如果在一个方法里同时使用了两个数据源:例如
DbZhUtil zhdb = DbZhUtil.getInstance();
DbYsUtil ysdb = DbYsUtil.getInstance();
调用该方法时会报这个错java.sql.SQLException: Connection has already been created in this tx context for pool named <first pool's name>. Illegal attempt to create connection from another pool: <second pool's name>" when you attempt to get the connection from the second non-XA connection pool.
Q:Can I use more than one non-XA connection pool in distributed transactions?
A:No. Even if you set EnableTwoPhaseCommit=true for both TxDataSources of the connection pools, attempting to use two non-XA connection pools in the same distributed transaction will result in "java.sql.SQLException: ...."
<container-transaction>
<method>
<ejb-name>CpxxBean</ejb-name>
<method-intf>Remote</method-intf>
<method-name>getTjzcs</method-name>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
</assembly-descriptor>