Hibernate utilizes Simple Logging Facade for Java
(SLF4J) in order to log various system events. SLF4J can direct your logging output to
several logging frameworks (NOP, Simple, log4j version 1.2, JDK 1.4 logging, JCL or logback) depending on your
chosen binding. In order to setup logging properly you will need slf4j-api.jar
in
your classpath together with the jar file for your preferred binding - slf4j-log4j12.jar
in the case of Log4J. See the SLF4J documentation for more detail.
To use Log4j you will also need to place a log4j.properties
file in your classpath,
an example properties file is distributed with Hibernate in the src/
directory.
We strongly recommend that you familiarize yourself with Hibernate's log messages. A lot of work has been put into making the Hibernate log as detailed as possible, without making it unreadable. It is an essential troubleshooting device. The most interesting log categories are the following:
Table 3.9. Hibernate Log Categories
Category | Function |
---|---|
org.hibernate.SQL |
Log all SQL DML statements as they are executed |
org.hibernate.type |
Log all JDBC parameters |
org.hibernate.tool.hbm2ddl |
Log all SQL DDL statements as they are executed |
org.hibernate.pretty |
Log the state of all entities (max 20 entities) associated with the session at flush time |
org.hibernate.cache |
Log all second-level cache activity |
org.hibernate.transaction |
Log transaction related activity |
org.hibernate.jdbc |
Log all JDBC resource acquisition |
org.hibernate.hql.ast.AST |
Log HQL and SQL ASTs during query parsing |
org.hibernate.secure |
Log all JAAS authorization requests |
org.hibernate |
Log everything (a lot of information, but very useful for troubleshooting) |
When developing applications with Hibernate, you should almost always work with
debug
enabled for the category org.hibernate.SQL
,
or, alternatively, the property hibernate.show_sql
enabled.