java.sql.SQLException: Connection has already been created in this tx context for pool named ...
2013-08-23 13:19
726 查看
在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: ...."
分布式事务中不支持多个non-XA的数据源
解决办法有三个:
1. 使用XA connection Pool。在weblogic数据源配置时使用带XA的数据库驱动,但是XA因为要支持全局事务效率可能会不如不带XA的好。
2. 不使用全局事务。在weblogic数据源配置时仍配置non-XA的数据源,但在事物处理选项卡中将支持全局事物处理的选择勾掉,将不再支持多数据源的全局 (XA) 事务处理,只支持非全局 (本地) 事务处理。
3.指定bean或method不使用事务。在ejb-jar.xml中配置指定bean或method的
<assembly-descriptor>
<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>
,或者在方法上注入
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public String getTjzcs(String khdh, String cpdm) {
}
NotSupported 这种模式下,组件方法不支持事务,同时也会忽略掉调用程序中的事务对象,组件方法中的逻辑不受客户程序事务的提交或回滚的影响。
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: ...."
分布式事务中不支持多个non-XA的数据源
解决办法有三个:
1. 使用XA connection Pool。在weblogic数据源配置时使用带XA的数据库驱动,但是XA因为要支持全局事务效率可能会不如不带XA的好。
2. 不使用全局事务。在weblogic数据源配置时仍配置non-XA的数据源,但在事物处理选项卡中将支持全局事物处理的选择勾掉,将不再支持多数据源的全局 (XA) 事务处理,只支持非全局 (本地) 事务处理。
3.指定bean或method不使用事务。在ejb-jar.xml中配置指定bean或method的
<assembly-descriptor>
<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>
,或者在方法上注入
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public String getTjzcs(String khdh, String cpdm) {
}
NotSupported 这种模式下,组件方法不支持事务,同时也会忽略掉调用程序中的事务对象,组件方法中的逻辑不受客户程序事务的提交或回滚的影响。
相关文章推荐
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- 静态或动态导入和java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response解决方案
- java.lang.IllegalStateException: getOutputStream() has already been called for this response问题
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.sql.SQLException: nontx connection pool is full?
- JAVA异常 getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- getOutputStream() has already been called for this response java.lang.IllegalStateException: getOutp
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response的解决办法
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getWriter() has already been called for this response
- mysql出现Connection.close() has already been called. Invalid operation in this state.
- 解决java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response