spring.jpa.properties.hibernate.generate_statistics = true不起作用

时间:2019-08-13 13:23:02

标签: hibernate spring-boot jpa

无法启用休眠统计信息

嗨。 我目前正在寻找优化数据库持久性的方法。 我在SpringBoot服务中使用的是JPA Hibernate,我想检查查询是否使用批处理。

要进行检查,我需要启用休眠统计信息日志。 我已经在我的application.properties中添加了这两个:

spring.jpa.properties.hibernate.generate_statistics = true

logging.level.org.hibernate.stat =调试

但是看来我的应用程序无视这些设置。

您知道为什么不显示统计信息吗?

谢谢。

2 个答案:

答案 0 :(得分:2)

hibernate-core-5.4.10.Final出现了同样的问题,这为我启用了统计信息:

<logger name="org.hibernate.engine.internal.StatisticalLoggingSessionEventListener" level="INFO"/>

我的日志文件中的示例输出:

2020-02-13 17:27:57,188 [main]  INFO (o.h.e.i.StatisticalLoggingSessionEventListener:258 end) - Session Metrics {
    700 nanoseconds spent acquiring 1 JDBC connections;
    0 nanoseconds spent releasing 0 JDBC connections;
    2500 nanoseconds spent preparing 1 JDBC statements;
    678100 nanoseconds spent executing 1 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;
    939200 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)

答案 1 :(得分:0)

我遇到了类似的问题。

尝试检查您的日志记录配置文件,该文件可能会阻止此输出。 简单的方法是禁用您的日志记录配置文件,例如重命名它。

对于我来说,我将logback-srping.xml重命名为a-logback-spring.xml。并重新启动我的服务后。有用。

enter image description here

希望这会有所帮助。