开发者

Problem with SQL Connection

开发者 https://www.devze.com 2023-01-16 22:05 出处:网络
I am working on a project which uses Java,Spring and Hibernate. I just came across a situaition like this.

I am working on a project which uses Java,Spring and Hibernate. I just came across a situaition like this.

bean 1 :

<bean id="cat" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="proxyInterfaces">
        &开发者_StackOverflowlt;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>

but while executing a getting the following exception

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)

Assume cat and dog are two differnt interfaces

cant we have two transaction manager opened ??


Although this is about weblogic the answer might match your problem: http://objectmix.com/weblogic/549975-connection-has-already-been-created-tx-context-pool-named.html

And the answer is basically: No you can't

The problem is that you can't use two connection pools in one transaction. = A solution is to have a separate method in the bean which is used to call profilePool, and have this method set to TRANSACTION-NOTSUPPORTED, so that the read-only work on profile pool takes place outside of the transaction o= n vcheqPool (I think the error message is saying that profilePool is the read-only one - if not swap 'profilePool and vcheqPool around where they appeared earlier)

In order to use connections from two or more databases in one transaction, you will have to do the following:

  • Both drivers must be XA compliant
  • You have to use TXDataSources
  • You need a global transaction, either through the container (SessionBean with "Requires") or through UserTransaction

When you meet all of these requirements, you will be able to use connections from more than one DataSource in one transaction.

0

精彩评论

暂无评论...
验证码 换一张
取 消