Home >Database >Mysql Tutorial >How Can I See the Exact SQL Queries Executed by Hibernate?
How to view the actual SQL query in Hibernate
While setting hibernate.show_sql=true
in the configuration file can display SQL queries, these queries may not accurately reflect the queries ultimately sent to the database. If you need to see the actual SQL code, there are several ways.
Use JDBC driver proxy
Tools like P6Spy or log4jdbc can act as a JDBC-driven proxy, allowing you to intercept and format SQL queries sent to the database.
Enable logging
Alternatively, you can enable logging in log4j.properties
for the following categories:
<code>log4j.logger.org.hibernate.SQL=DEBUG log4j.logger.org.hibernate.type=TRACE</code>
This will log the SQL query in a format similar to your example, including bind parameters:
<code>select employee.code from employee where employee.code=12</code>
Reference materials
The above is the detailed content of How Can I See the Exact SQL Queries Executed by Hibernate?. For more information, please follow other related articles on the PHP Chinese website!