Show Hibernate SQL Query in Spring Boot

Show-Hibernate-SQL-Query-in-Spring-Boot

In this post, I am going to share how to show Hibernate SQL queries on the console log while running your Spring Boot project(s).

Spring Boot Console

Enable Hibernate SQL Queries Logging

To show hibernate SQL queries in the Spring Boot log file you will need to update the application.properties file with the following details:

logging.level.org.hibernate.SQL=debug

Show SQL Values

Additionally, to logging Hibernate SQL Queries, you can make your Spring Boot show the values which are being used in the SQL query, update application.properties file by adding the following line:

logging.level.org.hibernate.type.descriptor.sql=trace

Show JPA SQL Queries

If you use Spring Data JPA then you can log SQL queries by updating your application.properties file by adding:

spring.jpa.show-sql=trueCode language: JavaScript (javascript)

Format Hibernate SQL Query

You can also make SQL queries display in your log file in a very friendly-to-read format. To format SQL queries add the following property to application.properties file.

spring.jpa.properties.hibernate.format_sql=trueCode language: JavaScript (javascript)

Leave a Reply

Discover more from BHUTAN IO

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top