Home >Database >Mysql Tutorial >How to Log Detailed SQL Queries with Parameter Values in Hibernate?
When using Hibernate, it is often useful to view the SQL queries that are executed, especially when debugging or optimizing performance. However, by default, Hibernate logs SQL statements using placeholders (question marks) instead of the actual values of query parameters.
If you need to print queries that contain actual values, you can configure the following categories of logging:
For example, using log4j configuration:
<code># 记录SQL语句 log4j.logger.org.hibernate.SQL=debug # 记录传递给查询的JDBC参数 log4j.logger.org.hibernate.type=trace </code>
The first setting (org.hibernate.SQL) is equivalent to setting the hibernate.show_sql=true legacy property. The second setting (org.hibernate.type) prints binding parameters and other information.
Another way to print queries containing actual values is to use a JDBC proxy driver such as P6Spy. This driver intercepts all SQL statements and logs information with detailed information, including the actual values of query parameters.
The above is the detailed content of How to Log Detailed SQL Queries with Parameter Values in Hibernate?. For more information, please follow other related articles on the PHP Chinese website!