Difference between spring.jpa.properties.hibernate and spring.jpa.hibernate

I am working on a spring boot project and using spring data jpa with Hibernate as JPA implementation.

Currently in my application.yml I have the following properties,

spring:
    jpa:
        show-sql: true
        properties:
            hibernate:
                format_sql: true
                generate_statistics: true
        hibernate:
            ddl-auto: none
            dialect: org.hibernate.dialect.H2Dialect

There are Hibernate properties with different prefixes(spring.jpa.properties.hibernate and spring.jpa.hibernate)

What is the purpose of having these difference and can they be used interchangeably, meaning can I replace spring.jpa.properties.hibernate.format_sql with spring.jpa.hibernate.format_sql?


Solution 1:

This is explained in the Spring Boot documentation:

-- all properties in spring.jpa.properties.* are passed through as normal JPA properties (with the prefix stripped) when the local EntityManagerFactory is created.

So, spring.jpa.hibernate.X properties are used by Spring, and spring.jpa.properties are passed on to whatever JPA implementation you are using, allowing you to set configuration properties that Spring does not have.