【问题标题】:How to edit Hibernate settings in a Spring-Boot project?如何在 Spring-Boot 项目中编辑 Hibernate 设置?
【发布时间】:2017-08-08 16:59:26
【问题描述】:

基本上我要做的是将此属性更改添加到休眠状态,以便在其所有属性值为空时启用复合/可嵌入对象的实例化:

hibernate.create_empty_composites.enabled

我知道编辑 Hibernate 的常用方法是在 application.properties 文件中,如下所示:

################################################################################
#                               JPA MANAGEMENT                                 #
################################################################################
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true...
...
spring.jpa.properties.hibernate.create_empty_composites.enabled=true

但是spring.jpa.properties.hibernate.create_empty_composites.enabled=true 不起作用。我不确定 Spring 是否只是不识别某些属性,或者它只是放错了位置。

我想知道是否有其他方法可以直接编辑 Hibernate 属性,或者是否有其他修复方法。

【问题讨论】:

标签: spring hibernate jpa spring-boot spring-data-jpa


【解决方案1】:

分析

基本假设。您更有可能使用的是 Spring Boot 1.5.*。

  1. Spring Boot 1.5.* 使用 Hibernate 5.0.*。 GitHub proof

  2. Hibernate 从 5.1 版本开始支持 hibernate.create_empty_composites.enabled 设置。

解决方案

请考虑将 pom.xml 中的 Hibernate 依赖项升级到更新的版本(5.1 及更高版本)。

之后,它应该可以正常工作了:

此外,当创建本地 EntityManagerFactory 时,spring.jpa.properties.* 中的所有属性都作为普通 JPA 属性(去除前缀)传递。

——Spring Boot 1.5.* reference, 77. Data Access, 77.5 Configure JPA properties.

【讨论】:

    猜你喜欢
    • 2019-03-02
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 2018-12-12
    • 1970-01-01
    • 2019-07-02
    • 2017-08-03
    • 1970-01-01
    相关资源
    最近更新 更多