如何在Spring-Boot项目中编辑Hibernate设置?

时间:2017-08-08 16:59:27

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

基本上我尝试做的是将此属性更改添加到hibernate,以便在所有属性值为null时启用复合/可嵌入对象的实例化:

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属性,或者是否有其他修复方法。

1 个答案:

答案 0 :(得分:2)

分析

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

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

  2. 自5.1版以来,Hibernate支持hibernate.create_empty_composites.enabled设置。

  3. 解决方案

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

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

      

    此外,spring.jpa.properties.*中的所有属性都会在创建本地EntityManagerFactory时作为普通JPA属性(带有前缀已剥离)传递。

         

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