简体   繁体   中英

Atomikos Transaction Manager without Spring

I am trying to configure Atomikos Transaction without using spring.First i am trying to set up the EntityManagerFactory without using spring the following is code i have tried

private static AtomikosDataSourceBean prepareDataSource(){
        AtomikosDataSourceBean atomikosDataSourceBean = new AtomikosDataSourceBean();
        atomikosDataSourceBean.setUniqueResourceName("demo");
        atomikosDataSourceBean.setXaDataSourceClassName("oracle.jdbc.xa.client.OracleXADataSource");
        Properties properties = new Properties();
        properties.setProperty("user", "demo");
        properties.setProperty("password", "demo");
        properties.setProperty("URL", "dbc:oracle:thin:@localhost:1521/xe");
        atomikosDataSourceBean.setXaProperties(properties);
        return atomikosDataSourceBean;
    }


    public static EntityManagerFactory getEntityManagerFactory(){
        LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
        entityManagerFactory.setDataSource(prepareDataSource());
        entityManagerFactory.setPersistenceUnitName("demo");
        entityManagerFactory.setPersistenceXmlLocation("classpath*:META-INF/persistence.xml");
        Properties properties = new Properties();
        properties.setProperty("hibernate.transaction.jta.platform", "com.demo.AtomikosJtaPlatform");
        properties.setProperty("hibernate.show_sql", "true");
        return  (EntityManagerFactory) entityManagerFactory;

    }

The above code is returning me an classcastexception.How can i get the same entitymanagerfactory without using spring

I would refer to the official documentation of Atomikos, which actually contains an example for those who opt for not using Spring:

Atomikos without Spring

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM