2010-09-16 103 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