我试图摆脱persistence.xml
Spring JPA Web 应用程序中的典型文件。到目前为止,我已经成功地注入EntityManager
了以下内容:
@Configuration
@EnableTransactionManagement
public class JpaConfig {
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(){
LocalContainerEntityManagerFactoryBean factoryBean
= new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource( this.restDataSource() );
factoryBean.setPackagesToScan( new String[ ] { "com.jverstry" } );
factoryBean.setPersistenceUnitName("MyMy");
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(){
{
// JPA properties ...
}
};
factoryBean.setJpaVendorAdapter( vendorAdapter );
return factoryBean;
}
@Bean
public DataSource restDataSource(){
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
dataSource.setUrl("jdbc:hsqldb:mem:testdb");
dataSource.setUsername("sa");
dataSource.setPassword("");
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager(){
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(
this.entityManagerFactoryBean().getObject() );
return transactionManager;
}
}
我设法为数据源移动了我的 persistence.xml 的属性:
<properties>
...
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
但是如何设置上面剩下的两个休眠属性?谢谢