如何仅使用 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 .
编辑 PS:对于此行 hibernateProperties.setProperty("hibernate.hbm2ddl.auto","update");
查看此 stackoverflow question如果 update
不适合您,找出最佳值(value)。
关于java - 如何使用注释和纯 Java 在 Spring 中设置 hibernate.hbm2ddl.auto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32897640/