【问题标题】:spring.jpa.properties.hibernate.generate_statistics=true not workingspring.jpa.properties.hibernate.generate_statistics=true 不工作
【发布时间】:2019-08-13 13:23:02
【问题描述】:

无法启用休眠统计

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

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

spring.jpa.properties.hibernate.generate_statistics=true

logging.level.org.hibernate.stat=debug

但我的应用程序似乎忽略了这些设置。

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

谢谢。

【问题讨论】:

  • 可能是你的日志框架正在吃掉所有的日志,以防日志级别设置不正确。
  • 嗨@kedar。我正在使用 sl4j 并使用日志级别信息

标签: hibernate spring-boot jpa


【解决方案1】:

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

【讨论】:

  • 嗨,我也遇到了这个问题。使用 spring boot 2.3.0 和 spring.jpa.properties.hibernate.generate_statistics=true。其他 sql 配置工作,例如 spring.jpa.properties.hibernate.show_sql=true。还添加到记录器: 。有什么想法吗?
  • 使用 Spring Boot (2.3.1),您可以在应用程序属性文件中使用类似 logging.level.org.hibernate.engine.internal.StatisticalLoggingSessionEventListener=INFO 的内容来记录统计信息
【解决方案2】:

我遇到了类似的问题。

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

就我而言,我将 logback-srping.xml 重命名为 a-logback-spring.xml。并在重新启动我的服务后。有用。

希望这能有所帮助。

【讨论】:

    猜你喜欢
    • 2016-04-09
    • 2019-05-02
    • 2018-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2016-02-16
    相关资源
    最近更新 更多