如何在Spring JPA Web应用程序中设置一些Hibernate属性?
2022-09-02 09:42:47
我正在尝试摆脱Spring JPA Web应用程序中的典型文件。到目前为止,我已经设法成功地注入了以下内容:persistence.xml
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;
}
}
我已经设法移动了数据源的持久性.xml的属性:
<properties>
...
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
但是我如何设置上面剩下的两个休眠属性?谢谢