Showing posts with label hibernet. Show all posts
Showing posts with label hibernet. Show all posts

Monday, January 28, 2008

Hibernate SQL Logging

If you use Hibernate (2.x or 3.x), then you most probably already know how to turn on/off the SQL logging (to System.out).

This post is to show how you can weak small settings for log4j to enable the logging rather in a application log file than System.out. Also included is nifty tip to get the values which were assigned to the the prepared statements that hibernate would have used for retrieval of data from database.


[PS: This is nothing new. I am just posting here so that I can remember and may be some other guys would benefit from it]

  1. Basic SQL debugging on and off

  2. <property name="show_sql">true</property>
  3. Moving your SQL queries to Log a file using log4j configuration. Just add following lines into you log4j.properties.
  4. # setup for HQL to log
    log4j.logger.net.sf.hibernate.SQL=DEBUG, consoleName
    log4j.additivity.org.hibernate.SQL=false
  5. Logging the parameters passed to the Prepared statement to log file using log4.properties file setting.

  6. # to read the values attached to Prepared statments of Hibernate
    log4j.logger.net.sf.hibernate.type=DEBUG, consoleName
NOTE: If you are using hibernate 3.x then just replace net.sf.hibernate with org.hibernate in above log4j.properties file settings
That's all for now!

Regards,
Vijay Dharap