Is it possible in Hibernate to print generated SQL queries with real values instead of question marks?
How would you suggest to print queries with real values if it is not possible with Hibernate API?
Is it possible in Hibernate to print generated SQL queries with real values instead of question marks?
How would you suggest to print queries with real values if it is not possible with Hibernate API?
You can add category lines to log4j.xml:
and add hibernate properties:
Here is what worked for me, set below property in the log4j.file:
Hibernate properties settings :
Logging works but not exactly you want or i wanted some time ago, but P6Spy does work perfectly,
here is the simple tutorial to implement as well MKYONG tutorial for P6Spy.
for me it worked like charm.
Get the “p6spy-install.jar“
Extract the
p6spy-install.jar
file, look forp6spy.jar
andspy.properties
Add
p6spy.jar
into your project library dependencyModify your database configuration file. You need to replace your existing JDBC driver with P6Spy JDBC driver –
com.p6spy.engine.spy.P6SpyDriver
Original is MySQL JDBC driver –
com.mysql.jdbc.Driver
Changed it to P6Spy JDBC driver –
com.p6spy.engine.spy.P6SpyDriver
spy.properties
Replace the
real driver
with your existing MySQL JDBC driverChange the Log file location Change the log file location in logfile property, all SQL statements will log into this file.
Windows
*nix
“spy.properties”
to project classpathCopy
“spy.properties”
to your project root folder, make sure your project can locate “spy.properties”, else it will prompt“spy.properties”
file not found exception.The solution is correct but logs also all bindings for the result objects. To prevent this it's possibile to create a separate appender and enable filtering, for example:
if you are using hibernate 3.2.xx use
instead of