First, you must enable logging for the below categories:
Two different log categories and log levels to log executed SQL statements and their parameters which is used by Hibernate are explained below:
- For the org.hibernate.SQL category, SQL statements should be written as a DEBUG message.
- For the org.hibernate.type.descriptor.sql category, bind parameters should be logged in with log level TRACE.
In the log configuration, you can activate & deactivate them without depending on each other.
The following code snippet will explain log4j configuration which will activate both:
log4j.logger.org.hibernate.SQL=debug
# To log the SQL statements
log4j.logger.org.hibernate.type.descriptor.SQL=trace
#To log the JDBC parameters to the query.
Here, if you observe the first one is equivalent to hibernate.show_sql=true legacy property. Whereas, the second one prints the bound parameters among other things.