gpt4 book ai didi

java - SQL 连接问题

转载 作者:行者123 更新时间:2023-12-01 06:24:55 25 4
gpt4 key购买 nike

我正在开发一个使用 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)

假设猫和狗是两个不同的接口(interface)

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

最佳答案

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

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

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.

关于java - SQL 连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3726308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com