【问题标题】:Spring boot + Hibernate + Wildfly .. Log SQL statements and it's binding PARAMETERSSpring boot + Hibernate + Wildfly .. 记录 SQL 语句及其绑定参数
【发布时间】:2021-01-11 20:02:47
【问题描述】:

我有上面提到的设置,我在记录 SQL 绑定参数时遇到了一个大问题,我让它在 application.properties 文件中使用以下配置记录查询

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

为了记录绑定参数值,我尝试了以下属性,但没有成功。

logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type.descriptor.sql=trace
spring.jpa.properties.hibernate.SQL=debug
spring.jpa.properties.hibernate.type.descriptor.sql=debug
spring.jpa.properties.hibernate.type.descriptor.sql.BasicBinder=trace
spring.jpa.properties.hibernate.type=trace

那么,这里有什么我遗漏的东西吗,有没有配置可以解决这个问题? (Java 配置或属性?)或者我必须去截取 P6SPY 之类的数据源?

控制台日志示例:

15:09:42,116 INFO  [stdout] (default task-1) Hibernate: 
15:09:42,117 INFO  [stdout] (default task-1)     select
15:09:42,117 INFO  [stdout] (default task-1)         * 
15:09:42,117 INFO  [stdout] (default task-1)     from
15:09:42,117 INFO  [stdout] (default task-1)         ( select
15:09:42,117 INFO  [stdout] (default task-1)             notificati0_.NOTIFICATION_ID as notification_id1_27_,
15:09:42,117 INFO  [stdout] (default task-1)             notificati0_.COMMENT_ID_REF as comment_id_ref2_27_,
15:09:42,118 INFO  [stdout] (default task-1)             notificati0_.CREATED_AT as created_at3_27_,
15:09:42,118 INFO  [stdout] (default task-1)             notificati0_.DESCRIPTION_AR as description_ar4_27_,
15:09:42,118 INFO  [stdout] (default task-1)             notificati0_.DESCRIPTION_EN as description_en5_27_,
15:09:42,118 INFO  [stdout] (default task-1)             notificati0_.IDEA_ID_REF as idea_id_ref6_27_,
15:09:42,118 INFO  [stdout] (default task-1)             notificati0_.INITIATOR_ID as initiator_id7_27_,
15:09:42,118 INFO  [stdout] (default task-1)             notificati0_.NOTIFICATION_NAME as notification_name8_27_,
15:09:42,118 INFO  [stdout] (default task-1)             notificati0_.NOTIFICATION_TYPE_ID as notification_type_9_27_,
15:09:42,118 INFO  [stdout] (default task-1)             notificati0_.IS_READ as is_read10_27_,
15:09:42,119 INFO  [stdout] (default task-1)             notificati0_.TEAM_ID_REF as team_id_ref11_27_,
15:09:42,119 INFO  [stdout] (default task-1)             notificati0_.USER_PROFILE_ID as user_profile_id12_27_ 
15:09:42,119 INFO  [stdout] (default task-1)         from
15:09:42,119 INFO  [stdout] (default task-1)             OQ_IDEATE.NOTIFICATIONS_VIEW notificati0_ 
15:09:42,119 INFO  [stdout] (default task-1)         where
15:09:42,119 INFO  [stdout] (default task-1)             notificati0_.USER_PROFILE_ID=? ) 
15:09:42,120 INFO  [stdout] (default task-1)     where
15:09:42,120 INFO  [stdout] (default task-1)         rownum <= ?

先谢谢了。

【问题讨论】:

  • 我认为,你应该选择 P6SPY,它会省去很多麻烦,但不要在生产中使用日志记录。
  • @code_mechanic 我现在就去做,但我仍然认为有更好的方法来完成这项任务。当然,我不会在生产中应用它。感谢您的评论。

标签: java spring hibernate jpa wildfly


【解决方案1】:

试试这个

logging.level.org.hibernate.type=TRACE

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-19
    • 2015-03-15
    • 2015-09-02
    • 1970-01-01
    • 2017-11-29
    • 1970-01-01
    • 2020-02-27
    相关资源
    最近更新 更多