Configuring the application to be profile without changing the application code

While the easiest way to prepare the application to be profiled is to call

HibernateProfiler.initialize()

or use the Spring configuration, this may not be the preferred way of doing things.

Therefore, it is also possible to configure the application without this explicit initialization approach. The method of doing so is to include the following content in your log4j.xml file. You may add this to your application specific appenders and configuration:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

  <appender name="Hibernate.Profiler" 
    class="hibernatingrhinos.hibernate.profiler.appender.HibernateProfilerAppender">
    <layout class="org.apache.log4j.xml.XMLLayout" />
  </appender>
  
  <logger name="org.hibernate.transaction.JDBCTransaction">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>

  <logger name="org.hibernate.transaction.CMTTransaction">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>

  <logger name="org.hibernate.transaction.JTATransaction">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>
    
  <logger name="org.hibernate.SQL">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>

  <logger name="org.hibernate.impl.SessionImpl">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>    
    
  <logger name="org.hibernate.impl.AbstractSessionImpl">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>    

  <logger name="org.hibernate.event.def.DefaultLoadEventListener">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>    
    
  <logger name="org.hibernate.cache.StandardQueryCache">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>        

  <logger name="org.hibernate.persister.entity.AbstractEntityPersister">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>        

  <logger name="org.hibernate.loader.Loader">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>        

  <logger name="org.hibernate.jdbc.AbstractBatcher">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>

  <logger name="hibernatingrhinos.hibernate.profiler.cache.ProfilerQueryCache">
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </logger>    

  <root>
    <level value="TRACE"/>
    <appender-ref ref="Hibernate.Profiler"/>
  </root>

</log4j:configuration>