snippetjavaCritical
How to print a query string with parameter values when using Hibernate
Viewed 0 times
withhowhibernateparameterusingprintwhenstringvaluesquery
Problem
Is it possible in Hibernate to print generated SQL queries with real values instead of question marks?
How would you suggest to print queries with real values if it is not possible with Hibernate API?
How would you suggest to print queries with real values if it is not possible with Hibernate API?
Solution
You need to enable logging for the the following categories:
So a log4j configuration could look like:
The first is equivalent to
Another solution (non hibernate based) would be to use a JDBC proxy driver like P6Spy.
org.hibernate.SQL- set todebugto log all SQL DML statements as they are executed
org.hibernate.type- set totraceto log all JDBC parameters
So a log4j configuration could look like:
# logs the SQL statements
log4j.logger.org.hibernate.SQL=debug
# Logs the JDBC parameters passed to a query
log4j.logger.org.hibernate.type=traceThe first is equivalent to
hibernate.show_sql=true legacy property, the second prints the bound parameters among other things.Another solution (non hibernate based) would be to use a JDBC proxy driver like P6Spy.
Code Snippets
# logs the SQL statements
log4j.logger.org.hibernate.SQL=debug
# Logs the JDBC parameters passed to a query
log4j.logger.org.hibernate.type=traceContext
Stack Overflow Q#1710476, score: 577
Revisions (0)
No revisions yet.