cannot enlist more than one non-XA resource

本文针对使用多种方式操作多个数据源时出现的错误进行了解析,并提供了具体的解决方案。错误表现为无法注册超过一个非-XA资源的问题,通过调整数据源配置及采用特定的驱动来解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误场景:多个数据源三种操作方式并存。

(1) 关闭事务,使用jdbc执行建表语句

def.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);

(2)(3) 又使用了hibernate在不同sessionFacory之间切换执行sql。


错误代码:cannot enlist more than one non-XA resource, tried enlisting an XAResourceHolderState with uniqueName=dataSourceSCDP XAResource=a JDBC LrcXAResource in state NO_TX with XID null, already enlisted: an XAResourceHolderState with uniqueName=dataSource.1 XAResource=a JDBC LrcXAResource in state STARTED (started) with XID a Bitronix XID [3139322E3136382E35362E31000000000A6647B900000039 : 3139322E3136382E35362E31000000000A6647FE0000003A]


解决方案:

数据源的Driver使用 com.mysql.jdbc.jdbc2.optional.MysqlXADataSource.


同时附上datasouce配置:

<bean id="dataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource" init-method="init"
      destroy-method="close">
    <property name="className" value="${jdbc.driver}"/>
    <property name="uniqueName" value="dataSource"/>
    <!--the minimal amount of connections that can be in the pool.-->
    <property name="minPoolSize" value="${jdbc.minPoolSize}"/>
    <!--the maximum amount of connections that can be in the pool.-->
    <property name="maxPoolSize" value="${jdbc.maxPoolSize}"/>
    <!--the amount of seconds and idle connection can stay in the pool before getting closed.-->
    <property name="maxIdleTime" value="300"/>
    <!--the amount of connections to be created at once when the pool needs to grow.-->
    <property name="acquireIncrement" value="2"/>
    <!--the amount of time between failed connection acquirements.-->
    <property name="acquisitionInterval" value="1"/>
    <!--the amount of time in seconds a call to get a connection from the pool will wait when the pool is empty.-->
    <property name="acquisitionTimeout" value="2"/>
    <!--false only if the database can run many transactions on the same connection.-->
    <property name="deferConnectionRelease" value="true"/>
    <!--true if the transaction manager should allow mixing XA and non-XA transactions.-->
    <property name="allowLocalTransactions" value="true"/>
    <property name="applyTransactionTimeout" value="true"/>
    <!--Set whether connections in the ACCESSIBLE state can be shared within the context of a transaction.-->
    <property name="shareTransactionConnections" value="true"/>
    <property name="driverProperties">
        <props>
            <prop key="url">${jdbc.url}</prop>
            <prop key="user">${jdbc.username}</prop>
            <prop key="password">${jdbc.password}</prop>
        </props>
    </property>
    <property name="testQuery" value="SELECT 1"/>
</bean>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值