Search code examples
spring-bootjpaspring-data-jpa

Hibernate doesn't show SQL values


I have a Spring Boot application. Here my application.properties file

spring.datasource.url=jdbc:h2:mem:testdb;INIT=CREATE SCHEMA IF NOT EXISTS TEST
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.show-sql=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.sql.init.mode=always
spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true
spring.jpa.properties.hibernate.format_sql=true
server.port=8080
spring.jpa.defer-datasource-initialization=true

When I save some data I have output as below

Hibernate: 
    insert 
    into
        project.staff
        (school_name, tc) 
    values
        (?, ?)

I can't see the parameters which sent to DB. I have another API and it returns parameters as below

Hibernate: 
    insert 
    into
        price
        (brand_id, curr) 
    values
        (default, ?, ?, ?, ?, ?, ?, ?, ?)
2023-12-31 20:19:54.914 TRACE 47712 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [INTEGER] - [1]
2023-12-31 20:19:54.914 TRACE 47712 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [2] as [VARCHAR] - [EUR]

I have tried logging.level.org.hibernate.type=trace and it also didn't work.

I have checked multiple times application.properties file but I can't see the difference and I couldn't understand the problem. What I am missing to have parameters on logging?


Solution

  • You need to set the following logging properties to log SQL queries and parameters:

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