Home >Database >Mysql Tutorial >How Can I See the Exact SQL Executed by Hibernate?
Unlocking Hibernate's True SQL: A Deep Dive into Logging and Proxies
While setting hibernate.show_sql=true
displays SQL queries in your logs, these aren't always the exact statements sent to your database. This article explains how to see the precise SQL.
Revealing the Exact SQL:
To view the actual SQL code executed against your database, utilize one of these methods:
JDBC Driver Proxies: Employ tools like P6Spy or log4jdbc. These act as intermediaries between your application and the JDBC driver, intercepting and displaying the actual SQL statements.
Enhanced Logging: Configure your logging to include these categories:
<code>log4j.logger.org.hibernate.SQL=DEBUG log4j.logger.org.hibernate.type=TRACE</code>
The first setting mirrors hibernate.show_sql=true
, but the second provides crucial details about the bound parameters, completing the picture.
Further Reading:
The above is the detailed content of How Can I See the Exact SQL Executed by Hibernate?. For more information, please follow other related articles on the PHP Chinese website!