Seeing the SQL Hibernate produces |

Seeing the SQL Hibernate produces

There are two approaches here, one is to configure log4j to log useful information from Hibernate and the other is to use a JDBC driver wrapper which gives you beautiful logging of everything JDBC related, including the SQL which Hibernate produces.

Log4j for Hibernate 4

This gives you, depending on the JDBC driver, among other things, both the SQL and the parameter values:

It's up to the JDBC driver whether or not to implement the toString() method whith something sensible. The HSQL DB driver yields great results here, whereas the JTDS driver does not.

Log4j for Hibernate 3 & 4

# gives you the SQL with placeholder question marks where the values go

# gives you the values corresponding to  the question mark placeholder numbers

JDBC driver wrapper

Use log4jdbc which gives you the full SQL without any fuss.

Just turn on these log categories:


gmail torstein.k.johansen @ gmail ~ twitter @torsteinkrause ~