Spring Boot JPA 打印 SQL 执行时间

Spring Boot JPA About 997 words

需求

打印出JPA执行SQL语句时花费的时间。

添加配置

generate_statistics设置为true,表示生成统计信息。

spring:
  jpa:
    properties:
      hibernate:
        generate_statistics: true

输出:

2022-11-04 12:14:23.563  INFO 20760 --- [           main] i.StatisticalLoggingSessionEventListener : Session Metrics {
    113700 nanoseconds spent acquiring 1 JDBC connections;
    0 nanoseconds spent releasing 0 JDBC connections;
    1928400 nanoseconds spent preparing 2 JDBC statements;
    556300 nanoseconds spent executing 2 JDBC statements;
    0 nanoseconds spent executing 0 JDBC batches;
    0 nanoseconds spent performing 0 L2C puts;
    0 nanoseconds spent performing 0 L2C hits;
    0 nanoseconds spent performing 0 L2C misses;
    5434600 nanoseconds spent executing 1 flushes (flushing a total of 1 entities and 0 collections);
    0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)
}

参考

https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html

Views: 1,208 · Posted: 2023-03-02

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh