0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Display SQL statement generated by Hibernate JPA in Spring Boot environment

Posted at

Setup

I will show it by using my notice board example application (Spring Data JPA version). On file src/main/resources/application.properties, add following line

# if you set debug=true, no need to add first line
logging.level.org.hibernate.SQL=trace

logging.level.org.hibernate.type=trace

Start the application, you can see following log message on loading some page.

## SQL statement generated by JPA vendor library, "?" is place of parameter put into
2019-09-18 12:00:53.660 DEBUG 1436 --- [nio-8080-exec-4] org.hibernate.SQL                        : select message0_.id as id1_1_, message0_.approved_by as approved2_1_, message0_.approved_date as approved3_1_, message0_.description as descript4_1_, message0_.owner as owner5_1_, message0_.publish_date as publish_6_1_, message0_.remove_date as remove_d7_1_ from message message0_ where message0_.owner=? order by message0_.publish_date DESC
## first parameter bind into SQL statement
2019-09-18 12:00:53.660 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [VARCHAR] - [user1]

## 1st record returned
2019-09-18 12:00:53.661 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([id1_1_] : [BIGINT]) - [4]
2019-09-18 12:00:53.662 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([approved2_1_] : [VARCHAR]) - [null]
2019-09-18 12:00:53.662 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([approved3_1_] : [TIMESTAMP]) - [null]
2019-09-18 12:00:53.663 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([descript4_1_] : [VARCHAR]) - [Waiting approve message 1]
2019-09-18 12:00:53.663 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([owner5_1_] : [VARCHAR]) - [user1]
2019-09-18 12:00:53.663 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([publish_6_1_] : [TIMESTAMP]) - [2019-08-03T10:00]
2019-09-18 12:00:53.663 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([remove_d7_1_] : [TIMESTAMP]) - [null]
## 2nd record returned
2019-09-18 12:00:53.663 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([id1_1_] : [BIGINT]) - [5]
2019-09-18 12:00:53.664 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([approved2_1_] : [VARCHAR]) - [null]
2019-09-18 12:00:53.664 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([approved3_1_] : [TIMESTAMP]) - [null]
2019-09-18 12:00:53.664 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([descript4_1_] : [VARCHAR]) - [Waiting approve message 2]
2019-09-18 12:00:53.664 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([owner5_1_] : [VARCHAR]) - [user1]
2019-09-18 12:00:53.664 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([publish_6_1_] : [TIMESTAMP]) - [2019-08-03T10:00]
2019-09-18 12:00:53.664 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([remove_d7_1_] : [TIMESTAMP]) - [null]
## 3rd record returned
2019-09-18 12:00:53.664 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([id1_1_] : [BIGINT]) - [1]
2019-09-18 12:00:53.664 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([approved2_1_] : [VARCHAR]) - [admin]
2019-09-18 12:00:53.664 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([approved3_1_] : [TIMESTAMP]) - [2019-07-31T21:00]
2019-09-18 12:00:53.664 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([descript4_1_] : [VARCHAR]) - [Hello world]
2019-09-18 12:00:53.664 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([owner5_1_] : [VARCHAR]) - [user1]
2019-09-18 12:00:53.665 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([publish_6_1_] : [TIMESTAMP]) - [2019-08-01T12:30]
2019-09-18 12:00:53.665 TRACE 1436 --- [nio-8080-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([remove_d7_1_] : [TIMESTAMP]) - [null]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?