【问题标题】:SpringBoot 1.3.0 support hibernate 5?SpringBoot 1.3.0 支持休眠 5?
【发布时间】:2016-03-11 11:58:42
【问题描述】:

我对 SpringBoot (1.3.0) 对 Hibernate5 的支持有点困惑。该参考文献列出了对 hibernate 4.3.11.Final 的依赖,但也列出了对 SpringFramework 4.2.3 的依赖,其中包括对 Hibernate5 的支持。

是否只是添加额外的 Hibernate5 依赖项来覆盖哪些 Boot 捆绑包?有人可以帮我澄清一下吗?

【问题讨论】:

    标签: java spring hibernate spring-boot hibernate-5.x


    【解决方案1】:

    您可以将 Hibernate 4.3 或 Hibernate 5.0 与 Spring Boot 1.3 一起使用。如您所见,Hibernate 4.3.x 是默认版本。

    要使用 Hibernate 5.0,您应该覆盖 Spring Boot 依赖项管理中的 hibernate.version 属性。假设您使用的是 Maven:

    <properties>
        <hibernate.version>5.0.5.Final</hibernate.version>
    </properties>
    

    使用 Hibernate 5.0 时,与使用 Hibernate 4.3.x 的一大区别是您将失去 Spring Boot 的自定义命名策略。由于在 Hibernate 5.0 中进行了重大更改,您将在启动时看到如下警告:

    2015-12-07 10:04:56.911  WARN 81371 --- [           main] org.hibernate.orm.deprecation            : HHH90000006: Attempted to specify unsupported NamingStrategy via setting [hibernate.ejb.naming_strategy]; NamingStrategy has been removed in favor of the split ImplicitNamingStrategy and PhysicalNamingStrategy; use [hibernate.implicit_naming_strategy] or [hibernate.physical_naming_strategy], respectively, instead.
    

    如果您不喜欢 Hibernate 5 的默认值,您可以分别使用 spring.jpa.properties.hibernate.implicit_naming_strategyspring.jpa.properties.hibernate.physical_naming_strategy 属性在 Spring Boot 的 application.properties 中指定自定义的隐式或物理命名策略。

    【讨论】:

    • 感谢您的详细回答,但请原谅我的无知,您能否详细说明如何迁移到休眠 5 而不会破坏任何已经存在的东西?是否有一种命名策略可以替代我们目前使用的org.hibernate.cfg.ImprovedNamingStrategy?或者,在 Spring boot 正式迁移之前暂时停止使用 Hibernate 5 是一个更好的决定?
    【解决方案2】:

    2016 年 7 月更新:随着 Spring Boot 1.4.0 的发布,默认 Hibernate 5 is used as the default JPA persistence provider


    现在有一段时间了ticket about migrating to Hibernate 5 - 似乎主要的挫折是一些名称策略不兼容。截至目前,门票目前预定1.4.0

    【讨论】:

    【解决方案3】:

    谢谢各位!经过多次试验,这个解决方案对我来说就像一个魅力!我实现了自定义策略并将它们设置在 application.yml 中,如下所示:

       jpa:
        database: MYSQL
        database-platform: org.hibernate.dialect.MySQL5Dialect
        properties:
            hibernate:
                implicit_naming_strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
                physical_naming_strategy: com.quicken.ups.entities.utils.DBFieldNamingStrategy
    

    【讨论】:

    • 在哪里可以找到 com.quicken.ups.entities.utils.DBFieldNamingStrategy 的代码?
    猜你喜欢
    • 1970-01-01
    • 2014-05-08
    • 2017-09-01
    • 2012-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多