微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用Annotations和纯Java在Spring中设置hibernate.hbm2ddl.auto

如何仅使用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以确定最佳值.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐