Quick revision
The short answer
For quick local checks, spring.jpa.show-sql=true prints SQL to standard output, but without parameter values and bypassing the logging system. The proper way is logging.level.org.hibernate.SQL=DEBUG for the statements and, in Hibernate 6, logging.level.org.hibernate.orm.jdbc.bind=TRACE for the bind values, with hibernate.format_sql=true for readability. For a complete picture at the JDBC level, including batches and timing, a proxy such as datasource-proxy or p6spy logs each statement with its parameters filled in.
What to remember
In this answer, we went from the quick spring.jpa.show-sql=true, which prints statements to standard output without values, to proper logging with org.hibernate.SQL at DEBUG and, in Hibernate 6, bind values with org.hibernate.orm.jdbc.bind at TRACE. format_sql and use_sql_comments make statements readable, and a JDBC proxy such as datasource-proxy or p6spy shows every statement with its parameters, timing and batch size, which is the best tool for checking batching and counting queries.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
For quick local checks, spring.jpa.show-sql=true prints SQL to standard output, but without parameter values and bypassing the logging system. The proper way is logging.level.org.hibernate.SQL=DEBUG for the statements and, in Hibernate 6, logging.level.org.hibernate.orm.jdbc.bind=TRACE for the bind values, with hibernate.format_sql=true for readability. For a complete picture at the JDBC level, including batches and timing, a proxy such as datasource-proxy or p6spy logs each statement with its parameters filled in.
Why this question is asked
Seeing the SQL that Hibernate runs is the first step in almost every JPA performance or correctness problem: an N+1 pattern, a missing join, a query with the wrong parameter. Yet the settings changed between Hibernate 5 and 6, and many tutorials still show logger names that no longer work. Interviewers ask this to check that we know the current settings and which ones are safe beyond our laptop. In this answer, we will look at show-sql and its limits, switch to proper logging, add bind parameters with the Hibernate 6 logger, make the output readable, and finish with JDBC-level proxies.
1The Quick Option and Its Limits
The simplest setting is spring.jpa.show-sql=true. Spring Boot passes it to Hibernate, which then prints each statement directly to standard output.
Notice two limits. The parameter appears only as a question mark, so we cannot see which value was used. And the output goes to System.out rather than through SLF4J and Logback, so it has no timestamp, no thread name, no trace id, and it cannot be switched on or off per environment through logging configuration. It is fine for a quick look in development, but it does not belong in production configuration.
2Logging SQL Through the Logger
Hibernate logs every statement it executes at DEBUG level under the logger org.hibernate.SQL. Enabling that logger gives us the same statements, but through the normal logging system, with all the context our log pattern includes.
This replaces show-sql; we should not enable both, or every statement is printed twice. Because it is a normal logger, we can enable it in a test profile, or temporarily on one production instance through the Actuator loggers endpoint, without a restart.
3Adding Bind Parameter Values in Hibernate 6
To see the values bound to each question mark, we enable a second logger at TRACE level. In Hibernate 6 it is org.hibernate.orm.jdbc.bind. Hibernate 5 used org.hibernate.type.descriptor.sql.BasicBinder, which is why older guides show that name; with Spring Boot 3 it no longer logs anything.
| Setting | Statement | Values | Through logger |
|---|---|---|---|
spring.jpa.show-sql=true | yes | no | no, standard output |
logging.level.org.hibernate.SQL=DEBUG | yes | no | yes |
logging.level.org.hibernate.orm.jdbc.bind=TRACE | no | yes | yes |
hibernate.format_sql=true | formatting only | no | affects both |
| datasource-proxy or p6spy | yes, as sent to JDBC | yes, inline | yes |
Each bind line names the parameter position, its JDBC type and the value. Be careful with this logger outside development: it writes real data values, which may include personal data or secrets, into the logs. In production, enable it only briefly, on one instance, and only where the logs are allowed to hold such data.
4Making It Readable
Hibernate prints each statement on one line by default, which is hard to read for queries with several joins. Setting format_sql spreads it over several lines with indentation. use_sql_comments adds a comment saying where the statement came from, such as the JPQL query, which helps when many queries look alike.
Formatting makes logs longer, so it suits development and tests better than production, where a single line is easier to search and parse.
5Logging at the JDBC Level With a Proxy
Hibernate's loggers show what Hibernate executes, but not always how: batching, execution time and statements run by other code such as JdbcTemplate or Flyway are not part of them. A JDBC proxy sits between the application and the real DataSource and logs every statement that passes through, from any library. datasource-proxy and p6spy are the common choices, and both have Spring Boot starters (check your version for the coordinates and property names).
Notice what this adds: the execution time in milliseconds, whether the statement was batched and how big the batch was, and the parameters inline. That makes a proxy the best tool for checking batching and for counting statements per request in tests, for example to assert that a list endpoint runs exactly 2 queries.
6Follow-up questions
Is it safe to leave org.hibernate.SQL at DEBUG in production?
Usually not. It logs every statement, which can mean thousands of lines per second on a busy service, adding cost and noise. Production visibility is better served by metrics, traces with statement spans and database-side statistics; enable the logger briefly on one instance when investigating.
How do I see slow queries only?
Hibernate 6.2 and later can log statements slower than a threshold with hibernate.log_slow_query, set in milliseconds, under a slow query logger (check your version for the exact names). Database-side slow query logs, such as log_min_duration_statement in PostgreSQL, catch slow statements from every client.
Why does show-sql print question marks even with bind logging on?
show-sql prints the prepared statement text, which always contains placeholders. The values are bound separately, so they appear only in the bind logger's own lines or inline in a JDBC proxy's output.
7Conclusion
In this answer, we went from the quick spring.jpa.show-sql=true, which prints statements to standard output without values, to proper logging with org.hibernate.SQL at DEBUG and, in Hibernate 6, bind values with org.hibernate.orm.jdbc.bind at TRACE. format_sql and use_sql_comments make statements readable, and a JDBC proxy such as datasource-proxy or p6spy shows every statement with its parameters, timing and batch size, which is the best tool for checking batching and counting queries.
Open with
There are a few levels. The quick one is spring.jpa.show-sql=true, but it prints to standard output, not through the logger, and shows question marks instead of values, so I only use it for a quick look locally.
Then, if they want more
The proper way is to set logging.level.org.hibernate.SQL to DEBUG, which logs every statement through SLF4J with timestamps, thread and trace ids, and can be switched per profile or at runtime through the Actuator loggers endpoint.
For bind values in Hibernate 6, which is what Spring Boot 3 uses, I set logging.level.org.hibernate.orm.jdbc.bind to TRACE; it prints each parameter's position, type and value. The old BasicBinder logger from Hibernate 5 no longer works. I add hibernate.format_sql to make long queries readable, and sometimes use_sql_comments to see which JPQL a statement came from.
I am careful with bind logging outside development, because it writes real data into the logs.
When I need the full picture, for example to check batching or count statements per request in a test, I use a JDBC proxy like datasource-proxy or p6spy, which logs every statement with parameters inline, execution time and batch size, including SQL from JdbcTemplate or other libraries.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Hibernate 6, Hibernate 5, Spring Boot 3
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Data JPA reference, Hibernate ORM documentation, Spring Framework reference, Transaction management
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How do you see the SQL that Hibernate executes, including bind parameter values, in a...": https://scrivio-interview-library.netlify.app/databases/jpa-performance/4128be7eb7/