Red Hat Training

A Red Hat training course is available for Red Hat JBoss Web Server

4.5. Logging

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 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.
It is recommended 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 4.9. Hibernate Log Categories

CategoryFunction
org.hibernate.SQLLog all SQL DML statements as they are executed
org.hibernate.typeLog all JDBC parameters
org.hibernate.tool. hbm2ddlLog 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.cacheLog all second-level cache activity
org.hibernate. transactionLog transaction related activity
org.hibernate.jdbcLog all JDBC resource acquisition
org.hibernate.hql. ast.AST Log HQL and SQL ASTs during query parsing
org.hibernate.secureLog all JAAS authorization requests
org.hibernate Log everything. This is a lot of information but it is 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.