How to set hibernate.format_sql in spring-boot?

JavaSpringSpring BootSpring Data-Jpa

Java Problem Overview


I'm using spring-boot autoconfiguration for database injection, with properties defined:

spring.jpa.database=POSTGRESQL
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

But how can I set the hibernate.format_sql=true? Is that not supported by spring boot?

Java Solutions


Solution 1 - Java

Spring Boot will let you set any available hibernate property using:

spring.jpa.properties.*

So spring.jpa.properties.hibernate.format_sql=true would work as well.

Check out this part of the documentation

Solution 2 - Java

If you are using yml format to declare Spring Boot properties, you can use:

spring:
  datasource:
  jpa:
    properties:
      hibernate.format_sql: true

Solution 3 - Java

jpa:
  hibernate:
    ddl-auto: update
  show-sql: true
  properties:
    hibernate.format_sql: true

Solution 4 - Java

This is very much available

spring.jpa.hibernate.format_sql=true

Solution 5 - Java

You can use : spring.jpa.properties.hibernate.format_sql=true

Apart from the documentation, I do follow example from here to configure my application. You can find a sample of properties being used in that.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmembersoundView Question on Stackoverflow
Solution 1 - JavageoandView Answer on Stackoverflow
Solution 2 - JavaAndrii AbramovView Answer on Stackoverflow
Solution 3 - JavaxiaogegeView Answer on Stackoverflow
Solution 4 - JavaAnkur SinghalView Answer on Stackoverflow
Solution 5 - JavaVinay VeluriView Answer on Stackoverflow