Hibernate Query String Printing with Parameter Values
It is often useful to examine the SQL queries generated by Hibernate, especially when troubleshooting issues. The default behavior of Hibernate is to display query strings with question marks (placeholders) for parameter values. However, it is possible to enable logging to view generated SQL queries with actual parameter values.
Enabling Hibernate Logging
To enable query string printing with parameter values, you need to configure Hibernate logging for the following categories:
Log4j Configuration
Here is an example Log4j configuration that enables logging for the specified categories:
# Logs the SQL statements log4j.logger.org.hibernate.SQL=debug # Logs the JDBC parameters passed to a query log4j.logger.org.hibernate.type=trace
Equivalent Legacy Property
The org.hibernate.SQL logger is equivalent to the legacy hibernate.show_sql=true property, which has been deprecated.
JDBC Proxy Drivers
An alternative approach is to use a JDBC proxy driver, such as P6Spy, which can capture and display SQL queries (including parameter values) without modifying the Hibernate configuration.
The above is the detailed content of How Can I Print Hibernate Query Strings with Parameter Values?. For more information, please follow other related articles on the PHP Chinese website!