Better Hibernate Logging with log4j
“I’m the Boss Man, Need the Info!”
Want to see not only the SQL statements that Hibernate generates, but also the parameters it binds to them, and the results it gets back? I did too.
Here’s how:
First, set Hibernate’s show_sql to false (if you’re using it)
Second, add the following to your log4j.properties file:
log4j.logger.org.hibernate.SQL=debug
log4j.logger.org.hibernate.type=trace
Log4j will now print out all Hibernate queries (as prepared statements, so there will be ?’s in them) and the values that are bound to the queries.
Other Alternatives
Do you want to see even more of what is going on at the SQL level? Have a look at p6spy – it will show you the actual SQL statements (with all parameters bound) that are sent to the database, and the result sets that are returned to your program.
Enjoy!
Enjoyed this post? Click to get future articles delivered by email or get the RSS feed.
