My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Tuesday, June 1, 2010

Enable DEBUG bind parameters in hibernate

Of late we had issues when using Hibernate and not able to identify the bind parameters when using PreparedStatement.

I am giving this for JBOSS server at this point of time, but will try to capture it for WLS also.

It would be pretty good if we have a stack trace like the following

Binding the following parameter to the SQL statement.

Here are the 2 ways to do it.



Change the jboss-4.2.2.GA\server\default\conf\jboss-log4j.xml

Add the following lines of code

<!-- Limit Hibernate categories --> 
   <category name="org.hibernate.type"> 
        <priority value="TRACE"/> 
        <appender-ref ref="CONSOLE"/>
   </category>
  
   <category name="org.hibernate.SQL"> 
           <priority value="TRACE"/> 
           <appender-ref ref="CONSOLE"/>
   </category>
  
Apart from this, in your hibernate configuration set the SHOW_SQL = true

Also on the sidelines, add these to your log4j property file.


log4j.category.org.hibernate.SQL=TRACE, STDOUT
log4j.category.org.hibernate.type=TRACE, STDOUT
log4j.category.net.sf.hibernate.type=TRACE, STDOUT
log4j.category.net.sf.ps.PreparedStatementCache=TRACE, STDOUT
### direct log messages to stdout ###
og4j.appender.STDOUT=org.apache.log4j.RollingFileAppender
log4j.appender.STDOUT.Threshold = TRACE
log4j.appender.STDOUT.File=C:\\hibernate.log
log4j.appender.STDOUT.MaxFileSize=10MB
log4j.appender.STDOUT.MaxBackupIndex=5
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%d{ISO8601} %-5p [%F:%L] : %m%n

No comments :