Debugging Hibernate using Log4J Logs

People who work with Hibernate often want to see, what SQL it is prepairing behind the seen and how it is mapping in real for debug purpose. We can achieve this by enable log4j for Hibernate classes. This will give a detailed debug info.

If using log4j.properties, enter the below line at end:

### log JDBC bind parameters ###
log4j.logger.net.sf.hibernate.type=debug

### log prepared statement cache activity ###
log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=debug

If using log4j XML file, enter below line before <root>:

<logger name="org.hibernate">
    <level value="debug"/>
</logger>

<logger name="org.hibernate.SQL">
    <level value="debug"/>
</logger>

<logger name="org.hibernate.type">
    <level value="debug"/>
</logger>

Happy Coding 🙂