Skip to main content

Hibernate Tip: How to view the values of Bind Variables

If you use Hibernate then you will have probably wanted at some point to see the underlying SQL that was being run. One solution is to enable SQL logging by increasing the Log4J logging levels of the org.hibernate packages.

There are two issues with this technique though:
  1. At DEBUG level you see the SQL but all bind variables are displayed as a ?
  2. At TRACE level you get everything and the kitchen sink, SQL, bind variables, results, etc. - it's very verbose!
Wouldn't it be nice if you could see the SQL and the bind variables without all the other Hibernate excessive tracing? Well my ex-colleague and good friend Andy Kayley has blogged about a solution that he found recently - check out his blog post:

How to Print Out Bind Variables in Java Prepared Statements

I've not tried it yet, but the next time I need to see the bind variable values I certainly will be!

Technorati Tags: , , , , , ,

Comments

Anonymous said…
Thanks for your blog. I could fix the prob in mins.