开发者

Atomikos AtomikosJTATransactionFactory giving ClassCastException

I was trying to implement Atomikos Transaction Manager in my code which is JPA on top of Hiberate. I'm getting this error. Any help highly appreciated.:

    Caused by: java.lang.ClassCastException: com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory
at org.hibernate.transaction.TransactionFactoryFactory.buildTransactionFactory(TransactionFactoryFactory.java:65)
at org.hibernate.cfg.SettingsFactory.createTransactionFactory(SettingsFactory.java:442)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:164)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:891)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)

These are my configurations:

Persistence.xml

<persistence-unit name="persistenceUnit"
    transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>xaDataSource</jta-data-source>
    <properties>
        <property name="hibernate.transaction.manager_lookup_class"
            value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup" />
    </properties>
</persistence-unit>

persistence-config.xml

<bean id="xaDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
    init-method="init" destroy-method="close">
    <property name="uniqueResourceName" value="dbResource" />
    <property name="xaDataSourceClassName" value="oracle.jdbc.xa.client.OracleXADataSource" />
    <property name="xaProperties">
        <props>
            &l开发者_开发百科t;prop key="serverName">${jdbc.server}</prop>
            <prop key="portNumber">1521</prop>
            <prop key="databaseName">${jdbc.database}</prop>
            <prop key="user">${jdbc.user}</prop>
            <prop key="password">${jdbc.password}</prop>
            <prop key="driverType">4</prop>
            <prop key="URL">${jdbc.url}</prop>
        </props>
    </property>
    <property name="maxPoolSize" value="60" />
    <property name="minPoolSize" value="1" />
</bean>


<bean id="pum"
    class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="persistenceXmlLocations">
        <list>
            <value>classpath:META-INF/persistence.xml</value>
        </list>
    </property>
    <property name="dataSources">
        <map>
            <entry key="xaDataSource" value-ref="xaDataSource" />
        </map>
    </property>

</bean>

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitManager" ref="pum" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database">
                <value>ORACLE</value>
            </property>
            <property name="databasePlatform">
                <value>${hibernate.dialect}</value>
            </property>
            <property name="showSql">
                <value>${hibernate.show_sql}</value>
            </property>
            <property name="generateDdl">
                <value>false</value>
            </property>
        </bean>
    </property>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
            <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
            <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
            <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</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">jta</prop>
        </props>
    </property>
</bean>

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

<bean id="userTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
    <property name="transactionTimeout">
        <value>100</value>
    </property>
</bean>

<bean id="JtaTransactionManager"
    class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager" ref="transactionManager" />
    <property name="userTransaction" ref="userTransaction" />
</bean>

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<!-- Activates the scanning of transaction like @transaction -->
<tx:annotation-driven transaction-manager="JtaTransactionManager" />

<!-- Translate native JPA Exceptions into Spring's DataAccessException hierarchy -->
<bean
    class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />


Found the solution. My project already had Hibernate dependency. I wrote this dependency in POM to exclude Hibernate with Atomikos. My best guess was that the issue is not Class Cast exception but a conflict of versions:

<dependency>
    <groupId>com.atomikos</groupId>
        <artifactId>transactions-hibernate3</artifactId>
        <version>${atomikos.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>hibernate</artifactId>
                <groupId>org.hibernate</groupId>
            </exclusion>
        </exclusions>
</dependency>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜