While setting show_sql
to true
in hibernate.cfg.xml
reveals SQL statements, this output might differ from the database's actual execution.
Discrepancies Between Displayed and Executed SQL
The show_sql
output undergoes modifications:
Accessing the True SQL
Two methods reveal the precise SQL:
1. Employing a JDBC Driver Proxy
Tools such as P6Spy or log4jdbc act as intermediaries between your application and the database, capturing the exact SQL queries.
2. Leveraging Log4j Configuration
Configure log4j using log4j.properties
as follows to log SQL queries and parameters:
<code>log4j.logger.org.hibernate.SQL=DEBUG log4j.logger.org.hibernate.type=TRACE</code>
Caution: Setting org.hibernate.type
to TRACE
generates extensive logs.
Further Reading:
The above is the detailed content of How Can I See the Exact SQL Hibernate Sends to the Database?. For more information, please follow other related articles on the PHP Chinese website!