@Configuration
public class JpaConfiguration {
@Value("#{dataSource}")
private javax.sql.DataSource dataSource;
@Bean
public Map<String, Object> jpaProperties() {
Map<String, Object> props = new HashMap<String, Object>();
props.put("hibernate.dialect", "");
props.put("hibernate.cache.provider_class", "");
return props;
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setShowSql(false);
hibernateJpaVendorAdapter.setGenerateDdl(false);
hibernateJpaVendorAdapter.setDatabase(Database.ORACLE);
return hibernateJpaVendorAdapter;
}
@Bean
public PlatformTransactionManager transactionManager() {
//JpaTransactionManager jpaTransactionManager=new JpaTransactionManager();
//jpaTransactionManager.setEntityManagerFactory(localContainerEntityManagerFactoryBean().getObject());
return new JpaTransactionManager( localContainerEntityManagerFactoryBean().getObject() );
}
@Bean
public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean() {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(this.dataSource);
lef.setJpaPropertyMap(this.jpaProperties());
lef.setJpaVendorAdapter(this.jpaVendorAdapter());
lef.setPersistenceUnitName("");
lef.setPackagesToScan("");
return lef;
}
}
Spring整合OpenJPA使用JAVA Configuration配置方式,零XML
最新推荐文章于 2024-09-02 00:15:00 发布