hibernate - spring.jpa.properties.hibernate.generate_statistics=true 不工作

标签 hibernate spring-boot jpa

无法启用 hibernate 统计

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

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

spring.jpa.properties.hibernate.generate_statistics=true

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

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

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

谢谢。

最佳答案

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

关于hibernate - spring.jpa.properties.hibernate.generate_statistics=true 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57478685/

相关文章:

java - application.yaml 中的 Hibernate 参数注释值

spring-boot - 运行 Spring Boot oAuth2 应用程序作为资源服务器并提供 Web 内容

java - 取消刷新尝试 : org. springframework.beans.factory.UnsatisfiedDependencyException: Spring Boot

java - 如何引发 OptimisticLockException

java - JPA Hibernate OneToMany 枚举 - 未映射的类错误

java - 在 Hibernate 中通过映射表值排序

java - 非映射属性的 Hibernate 标准

mysql - 如何使用 JPA/Hibernate 设置复合主键的列顺序

java - 找不到 hibernate.cfg.xml (intellij/maven)

jar - 为什么我无法提取 Spring Boot 可执行 jar?