Friday, August 28, 2009

Logging parameters for Hibernate's SQL statements

I spent a little time solving a problem this morning that I had previously solved a month or two ago, so I thought I should write down the solution!

It is often handy to see the exact SQL queries that Hibernate produces when it is interacting with the database. In order for the queries to be logged, the log4j.properties file is modified such that the log4j.logger.org.hibernate.SQL property is set to 'debug'. The problem is that while the queries themselves are logged correctly, the queries' parameters are not displayed at all.

There is a log4j.logger.org.hibernate.type property in the same file, however setting its value to 'debug' does not work. The solution is to set this property to 'trace', and then the parameters will be logged after the query itself has been logged.

0 Comments:

Post a Comment

<< Home