[JAVA] Spring Data JPA SQL log output

In Spring Data JPA, SQL is automatically generated according to the method name defined in Repository interface.

While I find it useful, I'm used to SQL, but I can't settle down without looking at the generated SQL.

Previously, I wrote how to log SQL using Log4JDBC. https://qiita.com/thankkingdom/items/add99a658302262b1645#log4jdbcを使ったsqlログ出力

~~ However, I couldn't use it because I couldn't download it via the in-house proxy. ~~ I'm using JUnit5 and I couldn't use Log4 JDBC JAR because it depends on junit4.

So, this time, I will introduce how to set it in application.properties.

#SQL log output
logging.level.org.hibernate.SQL=debug

#Bind parameter output
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=trace
logging.level.org.hibernate.type.EnumType=trace

▼ Addition With the following settings, only SQL was output. Not formatted in log format.

spring.jpa.show-sql=true
Reference site

https://qiita.com/sndr/items/af7d12be264c2cc4b252 http://www.ne.jp/asahi/hishidama/home/tech/java/spring/boot/jpa/index.html http://ice-black.hatenablog.com/entry/2018/04/29/164233

Recommended Posts

Spring Data JPA SQL log output
[spring] Let's use Spring Data JPA
[How to install Spring Data Jpa]
Spring Data JPA: Write a query in Pure SQL in @Query of Repository
Output system log by Spring AOP technology
Exists using Specification in Spring Data JPA
Output Spring Boot log in json format
Output request and response log in Spring Boot
Spring Data JPA Entity cross-reference and its notes
Request parameter log output sample Java & Spring MVC
Sort by Spring Data JPA (with compound key sort)
Creating a common repository with Spring Data JPA
Spring Boot + Spring Data JPA About multiple table joins
[Spring Batch] Output table data to CSV file
About Java log output
A memorandum when trying Spring Data JPA with STS
I tried to get started with Spring Data JPA
Until the use of Spring Data and JPA Part 2
Spring Data JDBC Preview
Until the use of Spring Data and JPA Part 1
Make the where clause variable in Spring Data JPA
spring data dynamodb trap
Output embedded Tomcat access log to standard output with Spring Boot
Spring Boot Introductory Guide I tried [Accessing Data with JPA]
[Spring] Controller exception output test
Control log output with Doma2
Java standard log output sample
Dynamically generate queries with Spring Data JPA (multi-word search) (paging support)
See the behavior of entity update with Spring Boot + Spring Data JPA
Creating REST APIs with Spring JPA Data with REST and Lombok incredibly easy.