Logging in Hibernate by R4R Team

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 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:

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. This is a lot of information but it is useful for troubleshooting


When developing applications with Hibernate, it should almost always work with debug enabled for the category org.hibernate.SQL, or, alternatively, the property hibernate.show_sql enabled.
Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!