Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (2.6k points)

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?

1 Answer

0 votes
by (46k points)

You require to permit logging for the following categories:

  • org.hibernate.SQL   - set to debug to log all SQL DML records as they are executed
  • org.hibernate.typesetet to follow to log all JDBC parameters

So a log4j configuration could seem like:

# logs the SQL statements

log4j.logger.org.hibernate.SQL=debug 

# Logs the JDBC parameters passed to a query

log4j.logger.org.hibernate.type=trace 

The first is similar to hibernate.show_sql=true legacy property, the second prints the bound parameters between other things.

Another resolution (not hibernate based) would be to use a JDBC proxy operator like P6Spy.

Related questions

0 votes
1 answer
asked Jul 26, 2019 in Java by Ritik (3.5k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...