Issue
With spring JPA is there a way to get valid sql in a log statement without the parameterized sql from the prepared statement.
I can see the SQL with my debug settings below, but the data is parameterized. Is there a way for it to generate sql like the following below.
Parameterized from log:
2021-12-12 17:54:37.414 DEBUG 10185 --- [ scheduling-1] org.hibernate.SQL
insert into DB2PROD.GLOBAL_TABLE (AGENT) values (?)
2021-12-12 17:54:37.415 TRACE 10185 --- [ scheduling-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [VARCHAR] - [N]
2021-12-12 17:54:37.415 TRACE 10185 --- [ scheduling-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - []
I see the values but I have to manually insert them to build the proper query. Is there something that would make it automatic.
Insert into table value('N') for example.
I am currently using this settings.
# Log Settings
logging.level.root: ${JPA_LOG_LEVEL}
logging.level.org.hibernate.SQL: ${JPA_LOG_LEVEL}
logging.level.org.hibernate.type.descriptor.sql.BasicBinder: ${JPA_LOG_LEVEL}
# Enable parameter binding (set to trace for param values), useful during debugging
# For most verbose logging, add in startup script:
# export JPA_LOG_LEVEL=TRACE
# export SQL_LOG_LEVEL=TRACE
logging.level.org.hibernate.type.descriptor.sql: trace
logging.level.org.hibernate.type.descriptor.type: trace
Solution
logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
The second line displays the prepared statement parameters
Answered By - jeff pentagon