0 votes
1 view
in SQL by (22.4k 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 (40.3k points)

First, you must enable logging for the below categories:

Two different log categories and log levels to log executed SQL statements and their parameters which is used by Hibernate are explained below:

  • For the org.hibernate.SQL category, SQL statements should be written as a DEBUG message.
  • For the org.hibernate.type.descriptor.sql category, bind parameters should be logged in with log level TRACE.

In the log configuration, you can activate & deactivate them without depending on each other. 

 The following code snippet will explain log4j configuration which will activate both:

log4j.logger.org.hibernate.SQL=debug

# To log the SQL statements

log4j.logger.org.hibernate.type.descriptor.SQL=trace

#To log the JDBC parameters to the query.

 Here, if you observe the first one is equivalent to hibernate.show_sql=true legacy property. Whereas, the second one prints the bound parameters among other things.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...