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?
Using Hibernate 4 and slf4j/log4j2 , I tried adding the following in my log4j2.xml configuration :
But without success.
I found out through this thread that the jboss-logging framework used by hibernate needed to be configured in order to log through slf4j. I added the following argument to the VM arguments of the application:
And it worked like a charm.
In case of spring boot is being used , just config this :
aplication.yml
aplication.properties
and nothing more.
HTH
Hibernate shows query and their parameter values in different lines.
If you are using application.properties in spring boot and you can use below highlighted parameter in application.properties.
org.hibernate.SQL will show queries
logging.level.org.hibernate.SQL=DEBUG
org.hibernate.type will show all parameter values, which will map with select , insert and update queries. logging.level.org.hibernate.type=TRACE
org.hibernate.type.EnumType will show enum type parameter value
logging.level.org.hibernate.type.EnumType=TRACE
example ::
sql.BasicBinder will show integer, varchar, boolean type parameter value
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
example ::
mysql jdbc driver has already provide a convenient to meet this requirement, you must at least the have the jar version >= mysql-connect-jar-5.1.6.jar
step 1: [configure your jdbc.url to add logger and custom logging]
now, it is using slf4j logging, if your default logging is log4j, you must add slf4j-api, slf4j-log4j12 dependencies to use slf4j logging
step 2: [write your custom logging]
Just for convenience, here is the same configuration example for Logback (SLF4J)
The output in your sql.log (example) then looks like this: