spring.jpa.properties.hibernate 和 spring.jpa.hibernate 之间的区别

Jav*_*ner 12 hibernate spring-data-jpa spring-boot

我正在开发一个Spring Boot项目并使用Spring Data JPAwithHibernate作为JPA实现。

目前在我的application.yml文件中我有以下属性:

spring:
    jpa:
        show-sql: true
        properties:
            hibernate:
                format_sql: true
                generate_statistics: true
        hibernate:
            ddl-auto: none
            dialect: org.hibernate.dialect.H2Dialect
Run Code Online (Sandbox Code Playgroud)

Hibernate 属性有不同的前缀(spring.jpa.properties.hibernatespring.jpa.hibernate

具有这些差异的目的是什么?它们可以互换使用,这意味着我可以替换spring.jpa.properties.hibernate.format_sqlspring.jpa.hibernate.format_sql

161*_*903 13

Spring Boot 参考文档的配置 JPA 属性对此进行了解释:

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

因此,spring.jpa.hibernate.X属性由 Spring 使用,并spring.jpa.properties传递给您正在使用的任何 JPA 实现,从而允许您设置 Spring 没有的配置属性。

  • 有人可以提供可能的“spring.jpa.properties.hibernate”属性文档的链接吗?更新:[找到了](https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/appendices/Configurations.html) ^_^ (3认同)
  • `spring.jpa.hibernate.X`的所有属性都可以放在`spring.jpa.properties.hiberante.X`中吗?spring 与 spring.jpa.hiberante.X 属性有什么关系? (2认同)