Wednesday, June 27, 2007

Hibernate Logging

Have you ever tried to get hibernate to log SQL? It's quite easy, just set log4j.logger.org.hibernate.SQL=DEBUG, and hey presto, you have SQL statements logged. Except it's not too useful, as most of them are parameterised queries, with lists of question marks instead of values. So you do a search on Google and it turns up millions of entries saying you need to set log4j.logger.org.hibernate.type. But it doesn't help, because all the articles say the value should be INFO, whereas what you really want is log4j.logger.org.hibernate.type=TRACE.

So there you go. Maybe Google will turn up my blog entry instead for you.

5 comments:

Tim Church said...

Google did lead me to your blog. Just what I was looking for. Works great. Thanks!

Sam said...

thanks! Still doesn't show up all the ?s but I got enough extra debugging info to work out that I was persisting where I should be merging

Acrof said...

Do you mind to tell what arqchive I have to set the log4j.logger.org.hibernate.SQL?

Rosdi said...

Thank YOU!.. my ass is saved!!! All of because of you!!... tq tq tq tq!.. next time you come to my country I will buy you a drink.

HTWK2000 said...

in my blog i describe a other way to log (hibernate) sql-statements with a jdbc-logger. maven-ready and with spring-integration. have a look here : http://ahoehma.wordpress.com/2009/06/03/hibernate-sql-logging-with-values/