19

I recently upgraded my Spring Boot app to v3.0 which required Hibernate to be upgraded to v6.1.5.Final.

I'm using Spring Data JPA with Hibernate as the JPA provider. When I run the app locally, I want to log SQL statements and the values of any parameters in those statements. To this end, I've added the following to my local configuration, as per this blog post:

spring:
  jpa:
    show-sql: false
    properties:
      hibernate:
        format_sql: true
logging:
  level:
    org.hibernate.SQL: debug
    org.hibernate.type.descriptor.sql: trace

I'm pretty sure this worked prior to the upgrade, but now only the SQL statements are logged i.e. the parameter values are missing.

Is it possible to log the query parameter values when using Spring Boot v3.0 and Hibernate v6.1.5.Final?

2
  • Try adding this to your application.properties logging.level.org.hibernate.type.descriptor.sql.BasicBinder=trace Commented Dec 20, 2022 at 11:41
  • 1
    @SaifAhmad I tried it, but it also doesn't work Commented Dec 20, 2022 at 13:52

3 Answers 3

40

Logging SQL in Spring boot 3 with Hibernate 6:

  • logging.level.sql for SQL logging group including Hibernate SQL logger.
  • logging.level.org.hibernate.orm.jdbc.bind for showing the binding parameters

So this should work:

logging:
  level:
    sql: debug
    org.hibernate.orm.jdbc.bind: trace
Sign up to request clarification or add additional context in comments.

3 Comments

in my case i had to set the logging.level.root to TRACE for this to work, which opened the gates for all types of TRACE level logs, how can i avoid this ? @Dirk Deyne
here's my application.yml : logging: level: org: hibernate: orm: jdcb: bind: TRACE sql: DEBUG root: TRACE
@Abdou changing the root logging level will not change the output of the other logging levels.
2

These properties also work with spring boot version 3.x.x

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.orm.jdbc.bind=TRACE

Comments

1

This line in the application.properties is enough with Spring Boot 3.4.5 and Hibernate 6.

logging.level.org.hibernate.orm.jdbc.bind=TRACE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.