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
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