【发布时间】:2018-08-18 01:23:45
【问题描述】:
我在我的 spring 项目中设置了 hibernate,一旦在我的数据库中创建了表,它就可以正常工作,但是我希望我的 hibernate 自动为我创建表。我没有使用 xml 进行配置,我使用的是 application.properties 文件和 hibernateConfig.java 类。
application.properties
hibernate.format_sql = true
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
HibernateConfig.java
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
return properties;
}
任何建议将不胜感激!
【问题讨论】:
标签: java spring hibernate nhibernate-configuration