Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log SQL statements with query param values in Spring Boot 3/Hibernate 6

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?

like image 866
Antonio Dragos Avatar asked Dec 01 '25 09:12

Antonio Dragos


2 Answers

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
like image 146
Dirk Deyne Avatar answered Dec 04 '25 01:12

Dirk Deyne


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
like image 22
Francis Avatar answered Dec 04 '25 00:12

Francis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!