Posted by Jacob von Eyben on November 12th, 2009
That will log all sql statement, but the actual parameter values will not be logged.
To log the values bound to the hibernate prepared statements, you can turn on trace for the org.hibernate.type logger.
Unfortunately (apparently because of perfomance) the value of the org.hibernate.type logger is evaulated once in a static block, and cached, see: EnumType.java.
That prevents you from turning the log on and off during runtime using a simple jsp page like the log4jAdmin.jsp. Note that if it were possible you still had to add trace to the page as debug is currently the lowest value.
Of course there must be a reason why the hibernate implementation are caching the value of the org.hibernate.type logger, but I believe it is still valuable to be able to turn on sql logging with parameters at runtime.
For that purpose I came across the logDriver. A simple database driver written by Ryan Bloom, that is wrapping an existing jdbc driver.
To use the logdriver all you have to do is set the driver and connection url as follows:
Now you can turn on logging by setting the net.rkbloom.logdriver logger to debug.