In some situations, using an HQL or Criteria query may not provide what you want, or you may not know how changing the HQL or Criteria query will affect results. In such cases, you can configure Hibernate to show the generated SQL in a log file, or in the application console. A query analyzer can then trace or analyze the generated SQL.
The simplest way to show the generated SQL is by setting
hibernate.show_sql in the configuration properties file, or
show_sql in the configuration XML file, with
true. You can also forward the generated SQL in the log files by setting up Log4j to debug. Besides, there are specific categories for the SQL log output, providing full control on the SQL logging. To learn more about ...