如何仅使用 Java 和注释在 Spring 中设置以下内容?
<property name="hibernate.hbm2ddl.auto" value="update"/>
我应该是可以的,而且我确实相信让项目变得自由 xml 会干净很多。
PS:这应该不重要,但我在 Heroku 上运行它。
将其添加到 dataSource() 所在的类中,它解决了我的问题。
final Properties hibernateProperties() {
final Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", "update");
hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
hibernateProperties.setProperty("hibernate.show_sql", "true");
return hibernateProperties;
}
完整的例子在这里https://github.com/arose13/Heroku-Spring-Postgres-Example https://github.com/arose13/Heroku-Spring-Postgres-Example.
EDIT PS: 对于这条线hibernateProperties.setProperty("hibernate.hbm2ddl.auto","update");
看看这个堆栈溢出问题 https://stackoverflow.com/questions/438146/hibernate-hbm2ddl-auto-possible-values-and-what-they-do找出最佳值,如果update
不适合你。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)