How can I make Hibernate log the values it binds to prepared statements?
If I set property hibernate.show_sql=true
I get following kind of logging:
insert into tablename (field1, field2) values (?, ?)
I'd like also to know what values are bound to question marks.
I am using Hibernate 3.2.7.ga.
Hibernate executes all SQL queries and DML operations using prepared statements. Not only that prepared statements help to prevent SQL injection attacks, but they can help speed up query executions, especially when the underlying database provides an execution plan cache (e.g. Oracle, SQL Server).
Hibernate uses 2 different log categories and log levels to log the executed SQL statements and their bind parameters: The SQL statements are written as DEBUG messages to the category org.hibernate.SQL. The bind parameters are logged to the org.hibernate.type.descriptor.sql category with log level TRACE.
How do you configure Hibernate so that it writes the executed SQL statements and used bind parameters to the log file? Hibernate uses 2 different log categories and log levels to log the executed SQL statements and their bind parameters: The SQL statements are written as DEBUG messages to the category org.hibernate.SQL.
log4j. logger. org. hibernate. SQL= DEBUG This will log the Hibernate queries in the following manner, with question marks as place holders for bound parameters.
Hibernate writes the DDL SQL queries executed during schema migration to this log category. The names of the log levels are defined by your logging framework and define the amount and granularity of the log messages. You can assign a log level to each category.
You need to set the following logging category to TRACE
org.hibernate.type
And personally, I don't use the show_sql
property, I work with DEBUG
enabled for the category:
org.hibernate.SQL
This way, I have a single place to configure everything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With