SQL连接问题

时间:2010-09-16 11:43:44

标签: java hibernate spring

我正在开发一个使用Java,Spring和Hibernate的项目。 我刚刚遇到过像这样的情况。

bean 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>

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)

假设猫和狗是两个不同的界面

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

1 个答案:

答案 0 :(得分:-2)

虽然这与weblogic有关,但答案可能与您的问题相符:http://objectmix.com/weblogic/549975-connection-has-already-been-created-tx-context-pool-named.html

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

  

问题是您不能在一个中使用两个连接池   交易。 =解决方案是在bean中使用单独的方法   用于调用profilePool,并将此方法设置为   TRANSACTION-NOTSUPPORTED,以便对配置文件池执行只读工作   发生在交易之外o = n vcheqPool(我认为是   错误消息是说profilePool是只读的 - 如果没有   将'profilePool和vcheqPool交换在它们之前出现的地方)

     

为了在一个数据库中使用来自两个或多个数据库的连接   交易,您必须执行以下操作:

     
      
  • 两个驱动程序必须符合XA
  •   
  • 您必须使用TXDataSources
  •   
  • 您需要通过容器(SessionBean with“Requires”)或UserTransaction
  • 进行全局事务   
     

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

相关问题