加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 01:24:52 所属栏目:大数据 来源:网络整理
导读:如何仅使用Java和注释在Spring中设置以下内容. 我应该是可能的,我相信让xml项目免费更清洁. PS:这应该不重要,但我在Heroku上运行它. 最佳答案 将此添加到dataSource()所在的类,它修复了我的问题. final Properties hibernateProperties() { final Propertie

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读