Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To show SQL generated by Hibernate, set hibernate.show_sql=true. For readable output, add hibernate.format_sql=true; for ANSI-colored SQL, add hibernate.highlight_sql=true. If you need SQL sent through your application’s logging system or written to a log file, configure the org.hibernate.SQL logger instead.

Show Hibernate SQL in the console

Add these properties to hibernate.properties or the Hibernate configuration used by your application:

hibernate.show_sql=true
hibernate.format_sql=true
hibernate.highlight_sql=true

show_sql prints generated statements as they execute. Formatting and highlighting are optional: format_sql makes statements multiline and indented, while highlight_sql adds ANSI syntax colors. Hibernate documents all three settings in its configuration guide; the JdbcSettings reference lists them as false by default: JdbcSettings.

Send SQL through your logging framework

hibernate.show_sql writes directly to standard error, not through Hibernate’s logging API. That means it can bypass appenders, filters, and file routing configured in your application. To manage SQL alongside other application logs, set the org.hibernate.SQL category to DEBUG in your SLF4J logging implementation. Hibernate documents this alternative in its configuration guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For Log4j 2, the logger configuration can look like this:

logger.hibernate.name = org.hibernate.SQL
logger.hibernate.level = debug

Use the configuration syntax appropriate to your logging framework; the logger category is org.hibernate.SQL.

Show bound parameter values

Hibernate’s SQL output may contain question-mark placeholders such as ?. That is expected: SQL text and the values bound to its placeholders are separate diagnostics. To inspect JDBC bind values, enable TRACE for org.hibernate.orm.jdbc.bind. To inspect values extracted from result sets, enable TRACE for org.hibernate.orm.jdbc.extract. Hibernate’s configuration guide documents both categories.

Example Log4j 2 entries:

logger.jdbc-bind.name = org.hibernate.orm.jdbc.bind
logger.jdbc-bind.level = trace
logger.jdbc-extract.name = org.hibernate.orm.jdbc.extract
logger.jdbc-extract.level = trace

These categories can produce detailed diagnostic output, so enable them only where that level of visibility is appropriate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the right SQL diagnostic

Need Setting or logger What it provides
Quick console output hibernate.show_sql=true Generated SQL written directly to standard error.
SQL in application logs org.hibernate.SQL at DEBUG SQL routed through the logging framework.
Bound JDBC values org.hibernate.orm.jdbc.bind at TRACE Parameter-binding diagnostics in addition to SQL text.
Result-set extraction details org.hibernate.orm.jdbc.extract at TRACE Diagnostics about values extracted from JDBC result sets.
More readable SQL hibernate.format_sql=true Multiline, indented statements.
Colored SQL hibernate.highlight_sql=true ANSI syntax highlighting in output that supports it.

Spring Boot: why spring.jpa.show-sql may not appear in a log file

spring.jpa.show-sql is a Spring Boot configuration property that enables Hibernate’s console-style SQL display. Because hibernate.show_sql writes to standard error rather than the logging API, that output may not follow the same routing as messages written by your application’s logging framework. If you want SQL managed by that framework, configure org.hibernate.SQL at DEBUG instead. Use the property format and configuration location that match your Spring Boot version and application setup.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Other useful SQL diagnostics

Add comments to generated SQL

Set hibernate.use_sql_comments=true to add comments to generated statements. This can help connect a SQL statement with the HQL that produced it. See Hibernate’s JdbcSettings reference.

Log slow queries

hibernate.log_slow_query sets the minimum execution time, in milliseconds, for slow-query logging. Its documented default threshold is 0, which disables slow-query logging. See the JdbcSettings reference for details.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.