2010-09-16 102 views
1

我正在使用Java,Spring和Hibernate的项目。 我刚刚遇到这样的情况。SQL连接问题

豆1:

<bean id="cat" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> 
    <property name="proxyInterfaces"> 
     <list> 
      <value>cat</value> 
     </list> 
    </property> 
    <property name="transactionManager"> 
     <ref bean="transactionManager"/> 
    </property> 
    <property name="transactionAttributeSource"> 
     <ref bean="attributeSource"/> 
    </property>       
</bean> 

豆2:

<bean id="dog" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> 
    <property name="proxyInterfaces"> 
     <list> 
      <value>dog</value> 
     </list> 
    </property> 
    <property name="transactionManager"> 
     <ref bean="transactionManager"/> 
    </property> 
    <property name="transactionAttributeSource"> 
     <ref bean="attributeSource"/> 
    </property>       
</bean> 

,但在执行收到以下异常

org.springframework.jdbc.support.SQLErrorCodesFactory] Error while extracting database product name - falling back to empty error codes 
org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; 
    nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; 
    nested exception is java.sql.SQLException: Connection has already been created in this tx context for pool Illegal attempt to create connection from another pool 
Caused by: 
    at weblogic.jdbc.jts.Driver.getExistingConnection(Driver.java:613) 

假设猫与狗是两个不同的充接口

不能我们有两个事务管理器打开?

回答

-2

虽然这是有关WebLogic答案可能匹配您的问题:http://objectmix.com/weblogic/549975-connection-has-already-been-created-tx-context-pool-named.html

而答案基本上是:不,你不能

的问题是,你不能使用两个连接池在一个 交易。 =解决方案是在用于调用profilePool的bean 中有一个单独的方法,并将此方法设置为 TRANSACTION-NOTSUPPORTED,以便配置文件池 上的只读工作发生在事务外o = ñvcheqPool(我觉得 错误消息说profilePool是只读一个 - 如果不是 交换“profilePool和vcheqPool左右,他们出现较早)

为了在一个使用两个或多个数据库连接您必须执行以下操作:

  • 名两位车手都必须符合XA
  • 你必须使用TXDataSources
  • 你需要一个全球性的交易,或者通过容器(会话Bean与“要求”),或者通过UserTransaction的

当你满足了所有这些要求,您将能够在一个事务中使用来自多个DataSource的 连接。

+0

答案中的链接域已死。 – Pang 2017-07-11 07:27:52