如何使用 Spring Boot 3 记录 JPA 查询中绑定的 SQL 参数?

dse*_*ero 3 java spring hibernate jpa spring-boot

我想记录 JPA 查询中绑定的 SQL 参数,并发现以下配置适用于 Spring Boot 2.7.3:

# Show all queries
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
#Show SQL parameters binding
logging.level.org.hibernate.sql=debug
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=trace

Run Code Online (Sandbox Code Playgroud)

我使用 H2 内存数据库,并且正在尝试使用 JPA EntityManager 编写一些查询。

当我尝试将项目升级到 Spring Boot 3.0.0-RC1 时,我继续看到 SQL 查询,但不再显示参数绑定。

我尝试了一些不同的休眠和应用程序日志记录级别配置,但没有成功找到工作配置。

使用 Spring Boot 3 记录 SQL 绑定的正确方法是什么?

小智 12

尝试这个:

logging.level.org.hibernate.orm.jdbc.bind=trace
logging.level.org.hibernate.type=trace
logging.level.org.hibernate.stat=debug
Run Code Online (Sandbox Code Playgroud)

它在使用 Springboot 3.0.0 时对我有用

  • 对我来说,最重要的是这一行:“logging.level.org.hibernate.orm.jdbc.bind=trace” (2认同)