com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory 无法转换为 org.hibernate.resource.transaction.TransactionCoordinatorBuilder

com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory cannot be cast to org.hibernate.resource.transaction.TransactionCoordinatorBuilder

尝试使用 Atomikos 事务管理器连接两个不同的数据源时出现以下错误

原因:java.lang.ClassCastException:com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory 无法转换为 org.hibernate.resource.transaction.TransactionCoordinatorBuilder

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

<bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:Application.properties" />
</bean>

<bean id="oracleSessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="oraclesDataSource" />
    <property name="mappingResources">
        <list>
            <value>persons.hbm.xml </value>
        </list>
    </property>

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
            <!-- <prop key="hibernate.autocommit">true</prop>
            <prop key="hibernate.connection.isolation">3</prop> -->
            <prop key="hibernate.current_session_context_class">jta</prop>
            <prop key="hibernate.transaction.factory_class">
                com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory
            </prop>
            <prop key="hibernate.transaction.manager_lookup_class">
                com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
            </prop>
            <!-- <prop key="hibernate.current_session_context_class">thread</prop> -->
            <prop key="hibernate.c3p0.min_size">5</prop>
            <prop key="hibernate.c3p0.max_size">10</prop>
            <prop key="hibernate.c3p0.timeout">300</prop>
        </props>
    </property>

</bean>

<bean id="mysqlSessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="mysqlDataSource" />
    <property name="mappingResources">
        <list>
            <value>persons.hbm.xml </value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <!-- <prop key="hibernate.autocommit">ture</prop> 
            <prop key="hibernate.connection.isolation">3</prop> -->
            <prop key="hibernate.current_session_context_class">jta</prop>
            <prop key="hibernate.transaction.factory_class">
                com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory
            </prop>
            <prop key="hibernate.transaction.manager_lookup_class">
                com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
            </prop>

            <!-- <prop key="hibernate.current_session_context_class">thread</prop> -->
            <prop key="hibernate.c3p0.min_size">5</prop>
            <prop key="hibernate.c3p0.max_size">10</prop>
            <prop key="hibernate.c3p0.timeout">300</prop>
        </props>
    </property>

</bean>



<tx:annotation-driven proxy-target-class="true" />

<tx:jta-transaction-manager
    transaction-manager="atomikosTransactionManager" />

<tx:annotation-driven transaction-manager="atomikosTransactionManager"
    proxy-target-class="true" />

<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
    init-method="init" destroy-method="close">
    <property name="forceShutdown" value="false" />

</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction">
    <property name="transactionTimeout" value="300" />

</bean>


<tx:annotation-driven />
<bean id="transactionManager"
    class="org.springframework.transaction.jta.JtaTransactionManager"
    depends-on="atomikosTransactionManager,atomikosUserTransaction">
    <property name="transactionManager" ref="atomikosTransactionManager" />
    <property name="userTransaction" ref="atomikosUserTransaction" />
    <!-- <property name="allowCustomIsolationLevels" value="true" /> -->

</bean>

<bean id="mysqlDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
    init-method="init" destroy-method="close">
    <property name="uniqueResourceName">
        <value>mySqlDataSource</value>
    </property>
    <property name="xaDataSourceClassName">
        <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
    </property>
    <property name="xaProperties">
        <props>
            <prop key="databaseName">sys</prop>
            <prop key="serverName">localhost</prop>
            <prop key="port">3306</prop>
            <prop key="user">root</prop>
            <prop key="password">magesh123</prop>
            <prop key="url">jdbc:mysql://localhost:3306/sys</prop>
        </props>
    </property>
    <property name="minPoolSize">
        <value>1</value>
    </property>
</bean>


<bean id="oraclesDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
    init-method="init" destroy-method="close">
    <property name="uniqueResourceName">
        <value>OracleDataSource</value>
    </property>
    <property name="xaDataSourceClassName">
        <value>oracle.jdbc.xa.client.OracleXADataSource</value>
    </property>
    <property name="xaProperties">
        <props>
            <prop key="databaseName">XE</prop>
            <prop key="serverName">localhost</prop>
            <!-- <prop key="port">1521</prop> -->
            <prop key="user">system</prop>
            <prop key="password">magesh123</prop>
            <prop key="URL">jdbc:oracle:thin:@localhost:1521:XE</prop>
        </props>
    </property>
    <property name="minPoolSize">
        <value>1</value>
    </property>
</bean>



<bean id="persons" class="com.bnym.aal.poc.spring_jta.Persons">
</bean>

<bean id="App" class="com.bnym.aal.poc.spring_jta.App">
    <property name="springJtaDaoClass" ref="springJtaDaoClass" />
</bean>

<bean id="springJtaDaoClass" class="com.bnym.aal.poc.spring_jta.springJtaDaoClass">
    <property name="oracleSessionFactory" ref="oracleSessionFactory" />
    <property name="mysqlSessionFactory" ref="mysqlSessionFactory" />
    <property name="atomikosTransactionManager" ref="transactionManager" />
    <property name="persons" ref="persons" />

</bean>

将我的休眠事务管理器更改为低于一个并且事务管理器工作

    <prop key="hibernate.transaction.factory_class">
    org.hibernate.transaction.CMTTransactionFactory
    </prop>

请参阅下面的 Git url 了解 Atomikos 事务管理器上的 POC,以开箱即用地集成 Spring - JTA

https://github.com/mageshsrinivasulu/spring-jta.git