Spring Boot – Show Hibernate SQL query

Add the following lines in application.properties to log the Hibernate SQL query.

application.properties

#show sql statement
logging.level.org.hibernate.SQL=debug

#show sql values
logging.level.org.hibernate.type.descriptor.sql=trace

1. org.hibernate.SQL=debug

application.properties

logging.level.org.hibernate.SQL=debug

1.1 Select query.

Console

2017-02-23 21:36:42 DEBUG org.hibernate.SQL - select customer0_.id as id1_0_, 
	customer0_.created_date as created_date2_0_, customer0_.email as email3_0_, 
	customer0_.name as name4_0_ from customer customer0_

2. org.hibernate.type.descriptor.sql=trace

application.properties

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

2.1 Select query and its values.

Console

2017-02-23 21:39:23 DEBUG org.hibernate.SQL - select customer0_.id as id1_0_, 
	customer0_.created_date as created_date2_0_, customer0_.email as email3_0_, 
	customer0_.name as name4_0_ from customer customer0_

	2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([id1_0_] : [BIGINT]) - [1]
2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([created_date2_0_] : [TIMESTAMP]) - [2017-02-11 00:00:00.0]
2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([email3_0_] : [VARCHAR]) - [111@yahoo.com]
2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([name4_0_] : [VARCHAR]) - [mkyong]
2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([id1_0_] : [BIGINT]) - [2]
2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([created_date2_0_] : [TIMESTAMP]) - [2017-02-12 00:00:00.0]
2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([email3_0_] : [VARCHAR]) - [222@yahoo.com]
2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([name4_0_] : [VARCHAR]) - [yflow]
2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([id1_0_] : [BIGINT]) - [3]
2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([created_date2_0_] : [TIMESTAMP]) - [2017-02-13 00:00:00.0]
2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([email3_0_] : [VARCHAR]) - [333@yahoo.com]
2017-02-23 21:39:23 TRACE o.h.t.descriptor.sql.BasicExtractor - extracted value ([name4_0_] : [VARCHAR]) - [zilap]

2.2 Insert query and its values.

Console

2017-02-23 21:44:15 DEBUG org.hibernate.SQL - select customer_seq.nextval from dual
2017-02-23 21:44:15 DEBUG org.hibernate.SQL - insert into customer (created_date, email, name, id) values (?, ?, ?, ?)

2017-02-23 21:44:15 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [TIMESTAMP] - [Thu Feb 23 21:44:15 SGT 2017]
2017-02-23 21:44:15 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [VARCHAR] - [aa]
2017-02-23 21:44:15 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - [a]
2017-02-23 21:44:15 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [4] as [BIGINT] - [1]
Note
You might be interested in this article – Hibernate Logging Guide

References

  1. Spring Boot SLF4J Logging example

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Tam nguyen van
Guest
Tam nguyen van

Hello
I see your blog is good .
I am research about spingboot project . Can you sent me project blank about sping boot with (sping boot . Mysql . Fontent show html ) It is nessuccery for me . Thank you very much

Mygmail. Nvtamcntt@gmail.com

Raj
Guest
Raj

nice