Set the hibernate.cfg.xml
attribute to show_sql
in Hibernate's true
configuration file to view the SQL statements generated by Hibernate. However, the generated SQL may not always be in an easy-to-read format.
To see the actual SQL statement passed directly to the database, you can:
log4j.properties
files to enable logging for the following categories: <code>log4j.logger.org.hibernate.SQL=DEBUG log4j.logger.org.hibernate.type=TRACE</code>
The first category is equivalent to hibernate.show_sql=true
, while the second category prints binding parameters and other information.
Using the second method, you may see the following output:
<code>2023-02-27 16:01:18,226 DEBUG org.hibernate.SQL - select employee.code from employee where employee.code = ? 2023-02-27 16:01:18,232 TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [INTEGER] - [12]</code>
This will give you "real" SQL, similar to:
<code>select employee.code from employee where employee.code=12</code>
The above is the detailed content of How Can I See the Actual SQL Generated by Hibernate?. For more information, please follow other related articles on the PHP Chinese website!