cannot enlist more than one non-XA resource

来源:互联网 发布:mysql unix timestamp 编辑:程序博客网 时间:2024/06/02 01:59

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

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


0 0
原创粉丝点击