Hibernate has a built-in function to enable logging of all generated SQL statements to the console. You can enable it by adding a property show_sqlto the Hibernate configuration file hibernate.cfg.xml. This feature is good for troubleshooting basic issues and for seeing what Hibernate is doing.
hibernate.cfg.xml
show_sql
Enable logging of all generated SQL statements to the console
<property name="show_sql">true</property>
format_sql
Format the generated SQL statement to make it more readable, but takes up more screen space.
<property name="format_sql">true</property>
use_sql_comments
Hibernate will post comments inside all generated SQL statements to hint that the generated SQL is trying to do
<property name="use_sql_comments">true</property>
log4j.properties
log4j.logger.org.hibernate=INFO, hb
log4j.logger.org.hibernate.SQL=DEBUG ## is equivalent to hibernate.show_sql=true
log4j.logger.org.hibernate.type=TRACE ## allows you to see the binding parameters
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug
log4j.appender.hb=org.apache.log4j.ConsoleAppender
log4j.appender.hb.layout=org.apache.log4j.PatternLayout
log4j.appender.hb.layout.ConversionPattern=HibernateLog --> %d{HH:mm:ss} %-5p %c - %m%n
log4j.appender.hb.Threshold=TRACE
log4j.logger.org.hibernate.tool.hbm2ddl=debug
To print the binding parameters, add the following to the log4j.properties file:
log4j.logger.net.sf.hibernate.type=debug