我试图在不使用spring的情况下配置Atomikos事务。首先我试图在不使用spring的情况下设置EntityManagerFactory以下是我试过的代码
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;
}
上面的代码给我一个classcastexception.How如何在不使用spring的情况下得到相同的entitymanager;