Atomikos Forum

Failed convert UserTransactionManager to PlatformTransactionMan.

Help :

org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'com.atomikos.icatch.jta.UserTransactionManager' to required type 'org.springframework.transaction.PlatformTransactionManager'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.atomikos.icatch.jta.UserTransactionManager] to required type [org.springframework.transaction.PlatformTransactionManager]: no matching editors or conversion strategy found
    at org.springframework.beans.SimpleTypeConverter.convertIfNecessary(SimpleTypeConverter.java:58) ~[spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.beans.SimpleTypeConverter.convertIfNecessary(SimpleTypeConverter.java:43) ~[spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1097) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.test.context.transaction.TransactionalTestExecutionListener.getTransactionManager(TransactionalTestExecutionListener.java:310) [spring-test-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:160) [spring-test-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:358) [spring-test-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73) [spring-test-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) [spring-test-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) [spring-test-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) [spring-test-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) [junit-4.8.1.jar:na]
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) [junit-4.8.1.jar:na]
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) [junit-4.8.1.jar:na]
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) [junit-4.8.1.jar:na]
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) [junit-4.8.1.jar:na]
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) [junit-4.8.1.jar:na]
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) [spring-test-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236) [junit-4.8.1.jar:na]
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) [spring-test-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) [.cp/:na]
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) [.cp/:na]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) [.cp/:na]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) [.cp/:na]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) [.cp/:na]


I use :

org.hibernate hibernate-entitymanager 3.6.10.Finalm org.hibernate hibernate-envers 3.6.10.Final
hibernate-validator 4.2.0.Final
org.hibernate hibernate-validator-annotation-processor 4.2.0.Finalorg
org.hibernate.javax.persistence hibernate-jpa-2.0-api 1.0.1.Final



com.atomikos atomikos-util 3.8.0
com.atomikos atomikos-util 3.8.0
            conf="compile->default; runtime->default"/>
        <dependency org="com.atomikos" name="transactions-api" rev="3.8.0"
            conf="compile->default; runtime->default"/>        
        <dependency org="com.atomikos" name="transactions" rev="3.8.0"
            conf="compile->default; runtime->default"/>
        <dependency org="com.atomikos" name="transactions-jdbc" rev="3.8.0"
            conf="compile->default; runtime->default"/>    
        <dependency org="com.atomikos" name="transactions-jta" rev="3.8.0"
            conf="compile->default; runtime->default"/>    
        <dependency org="com.atomikos" name="transactions-jms" rev="3.8.0"
            conf="compile->default; runtime->default"/>    
        <dependency org="com.atomikos" name="transactions-hibernate3" rev="3.8.0"
            conf="compile->default; runtime->default"/>
Serafim Tanev Send private email
Wednesday, June 13, 2012
 
 
import java.util.Properties;

import javax.inject.Inject;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;

import org.hibernate.cfg.ImprovedNamingStrategy;
import org.hibernate.dialect.PostgreSQLDialect;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.jta.JtaTransactionManager;

@EnableTransactionManagement
@Configuration
@ComponentScan(value = "at.repromedia.central.domain.base")
public class StoreConfiguration {

    // ...

    // this is a reference to a specific Java configuration class for JTA
    @Inject
    private AtomikosJtaConfiguration jtaConfiguration;

    // @Bean
    // public JmsTemplate jmsTemplate() throws Throwable{
    // JmsTemplate jmsTemplate = new JmsTemplate(jtaConfiguration.connectionFactory());
    // jmsTemplate.setSessionTransacted(true);
    // return jmsTemplate;
    // }

    @Bean
    public HibernateJpaVendorAdapter hibernateJpaVendorAdapter() {
        final HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
        hibernateJpaVendorAdapter.setDatabase(Database.POSTGRESQL);
        hibernateJpaVendorAdapter.setShowSql(true);
        return hibernateJpaVendorAdapter;
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManager() throws Throwable {
        final LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();

        entityManager.setPersistenceXmlLocation("classpath:**/persistence-test.xml");
        entityManager.setPersistenceUnitName("CentralDB");

        entityManager.setDataSource(jtaConfiguration.dataSource());
        entityManager.setJpaVendorAdapter(hibernateJpaVendorAdapter());

        final Properties properties = new Properties();
        properties.setProperty("hibernate.dialect", PostgreSQLDialect.class.getName());
        properties.setProperty("hibernate.ejb.naming_strategy", ImprovedNamingStrategy.class.getName());
        jtaConfiguration.tailorProperties(properties);
        entityManager.setJpaProperties(properties);

        return entityManager;
    }

    @Bean
    public PersistenceExceptionTranslationPostProcessor exceptionTranslationPostProcessor() {
        final PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor = new PersistenceExceptionTranslationPostProcessor();
        persistenceExceptionTranslationPostProcessor.setRepositoryAnnotationType(Service.class);
        return persistenceExceptionTranslationPostProcessor;
    }

    @Bean
    public PlatformTransactionManager platformTransactionManager() throws Throwable {
        final UserTransaction userTransaction = jtaConfiguration.userTransaction();
        final TransactionManager transactionManager = jtaConfiguration.transactionManager();
        return new JtaTransactionManager(userTransaction, transactionManager);
    }
}






import java.util.Properties;

import javax.inject.Inject;
import javax.sql.DataSource;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;

import org.postgresql.xa.PGXADataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.atomikos.icatch.jta.UserTransactionImp;
import com.atomikos.icatch.jta.UserTransactionManager;
import com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup;
import com.atomikos.jdbc.AtomikosDataSourceBean;

@Configuration
public class AtomikosJtaConfiguration {

    @Inject
    private Environment environment;

    public void tailorProperties(final Properties properties) {
        properties.setProperty("hibernate.transaction.manager_lookup_class", TransactionManagerLookup.class.getName());
    }

    @Bean
    public UserTransaction userTransaction() throws Throwable {
        final UserTransactionImp userTransactionImp = new UserTransactionImp();
        userTransactionImp.setTransactionTimeout(1000);
        return userTransactionImp;
    }

    @Bean(initMethod = "init", destroyMethod = "close")
    public TransactionManager transactionManager() throws Throwable {
        final UserTransactionManager userTransactionManager = new UserTransactionManager();
        userTransactionManager.setForceShutdown(false);
        return userTransactionManager;
    }

    @Bean(initMethod = "init", destroyMethod = "close")
    public DataSource dataSource() {
        final PGXADataSource pgXaDataSource = new PGXADataSource();
        pgXaDataSource.setApplicationName("central");
        pgXaDataSource.setServerName("localhost");
        pgXaDataSource.setPortNumber(5432);
        pgXaDataSource.setDatabaseName("central");
        pgXaDataSource.setPassword("central");
        pgXaDataSource.setUser("central");

        final AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
        xaDataSource.setXaDataSource(pgXaDataSource);
        xaDataSource.setUniqueResourceName("CentralDB");
        xaDataSource.setMaxPoolSize(5);
        xaDataSource.setBorrowConnectionTimeout(40);

        return xaDataSource;
    }

    // // jetzt ich brachuche das noch nicht !!!
    // @Bean(initMethod = "init", destroyMethod = "close")
    // public ConnectionFactory connectionFactory() {
    // final ActiveMQXAConnectionFactory activeMQXAConnectionFactory = new ActiveMQXAConnectionFactory();
    // activeMQXAConnectionFactory.setBrokerURL(this.environment.getProperty("jms.broker.url"));
    // final AtomikosConnectionFactoryBean atomikosConnectionFactoryBean = new AtomikosConnectionFactoryBean();
    // atomikosConnectionFactoryBean.setUniqueResourceName("xamq");
    // atomikosConnectionFactoryBean.setLocalTransactionMode(false);
    // atomikosConnectionFactoryBean.setXaConnectionFactory(activeMQXAConnectionFactory);
    // return atomikosConnectionFactoryBean;
    // }
}
Serafim Tanev Send private email
Wednesday, June 13, 2012
 
 
I have found the error.
Conflict with the defined Spring beans.

Bean userTransaction --> customUserTransaction
Bean transactionManager --> customTransactionManager

Old Version :
     @Bean
    public UserTransaction userTransaction() throws Throwable {
        logger.debug("userTransaction - BEGIN ");

        final UserTransactionImp userTransactionImp = new UserTransactionImp();
        userTransactionImp.setTransactionTimeout(1000);

        logger.debug("userTransaction - END ");
        return userTransactionImp;
    }

    @Bean(initMethod = "init", destroyMethod = "close")
    public TransactionManager transactionManager() throws Throwable {
        logger.debug("transactionManager - BEGIN ");

        final UserTransactionManager userTransactionManager = new UserTransactionManager();
        userTransactionManager.setForceShutdown(false);

        logger.debug("transactionManager - END ");

        return userTransactionManager;
    }


New Version :
    @Bean
    public UserTransaction customUserTransaction() throws Throwable {
        logger.debug("userTransaction - BEGIN ");

        final UserTransactionImp userTransactionImp = new UserTransactionImp();
        userTransactionImp.setTransactionTimeout(1000);

        logger.debug("userTransaction - END ");
        return userTransactionImp;
    }

    @Bean(initMethod = "init", destroyMethod = "close")
    public TransactionManager customTransactionManager() throws Throwable {
        logger.debug("transactionManager - BEGIN ");

        final UserTransactionManager userTransactionManager = new UserTransactionManager();
        userTransactionManager.setForceShutdown(false);

        logger.debug("transactionManager - END ");

        return userTransactionManager;
    }
Serafim Tanev Send private email
Thursday, June 14, 2012
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics