休眠统计在春靴不起作用?

我这里有一个小示例应用程序

https://github.com/jimbasilio/SpringBoot

这在数据库中创建了一些简单的数据,以及我正在研究的其他一些事情,以便在弹簧靴上踢轮胎(旁注:到目前为止,我喜欢弹簧靴!如果您克隆 git 存储库,则可以访问 url:

http://127.0.0.1:8080/hello/get/1

它将从数据库加载并将休眠统计信息写入控制台。

不过我确实遇到了一个问题,无论是否通过 application.properties 文件配置休眠统计信息:

hibernate.generate_statistics=true

当我写出休眠统计数据时,我没有得到任何有用的东西。我通过以下方式获取统计信息:

Session session = (Session) this.entityManager.getDelegate();
session.getSessionFactory().getStatistics().logSummary();
HelloEntity entity = helloRepository.findOne(id);
entityManager.flush();
session.getSessionFactory().getStatistics().logSummary();

我的第二条日志消息(刷新后)在下面。您可以看到它甚至没有注册正在打开的会话。我使用的是弹簧靴 1.0.1.RELEASE。

啪.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.0.1.RELEASE</version>
</parent>

日志文件:

2014-04-28 20:51:29.415  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000161: Logging statistics....
2014-04-28 20:51:29.416  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000251: Start time: 1398732682476
2014-04-28 20:51:29.416  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000242: Sessions opened: 0
2014-04-28 20:51:29.416  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000241: Sessions closed: 0
2014-04-28 20:51:29.416  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000266: Transactions: 0
2014-04-28 20:51:29.416  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000258: Successful transactions: 0
2014-04-28 20:51:29.417  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000187: Optimistic lock failures: 0
2014-04-28 20:51:29.417  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000105: Flushes: 0
2014-04-28 20:51:29.417  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000048: Connections obtained: 0
2014-04-28 20:51:29.417  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000253: Statements prepared: 0
2014-04-28 20:51:29.417  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000252: Statements closed: 0
2014-04-28 20:51:29.417  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000239: Second level cache puts: 0
2014-04-28 20:51:29.418  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000237: Second level cache hits: 0
2014-04-28 20:51:29.418  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000238: Second level cache misses: 0
2014-04-28 20:51:29.418  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000079: Entities loaded: 0
2014-04-28 20:51:29.418  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000080: Entities updated: 0
2014-04-28 20:51:29.418  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000078: Entities inserted: 0
2014-04-28 20:51:29.418  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000076: Entities deleted: 0
2014-04-28 20:51:29.419  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000077: Entities fetched (minimize this): 0
2014-04-28 20:51:29.419  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000033: Collections loaded: 0
2014-04-28 20:51:29.419  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000036: Collections updated: 0
2014-04-28 20:51:29.419  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000035: Collections removed: 0
2014-04-28 20:51:29.419  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000034: Collections recreated: 0
2014-04-28 20:51:29.420  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000032: Collections fetched (minimize this): 0
2014-04-28 20:51:29.420  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000438: NaturalId cache puts: 0
2014-04-28 20:51:29.420  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000439: NaturalId cache hits: 0
2014-04-28 20:51:29.420  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000440: NaturalId cache misses: 0
2014-04-28 20:51:29.420  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000441: Max NaturalId query time: 0ms
2014-04-28 20:51:29.420  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000442: NaturalId queries executed to database: 0
2014-04-28 20:51:29.420  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000210: Queries executed to database: 0
2014-04-28 20:51:29.420  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000215: Query cache puts: 0
2014-04-28 20:51:29.421  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000433: update timestamps cache puts: 0
2014-04-28 20:51:29.421  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000434: update timestamps cache hits: 0
2014-04-28 20:51:29.421  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000435: update timestamps cache misses: 0
2014-04-28 20:51:29.421  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000213: Query cache hits: 0
2014-04-28 20:51:29.421  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000214: Query cache misses: 0
2014-04-28 20:51:29.421  INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl  : HHH000173: Max query time: 0ms

答案 1

使用代替spring.jpa.properties.hibernate.generate_statistics=true
hibernate.generate_statistics=true


答案 2

我认为Hibernate只是没有阅读你的配置。

根据Hibernate的参考手册,你应该把Hibernate配置放在hibernate.properties或hibernate.cfg.xml上。如果这些不起作用,您可能还需要尝试编程配置。


推荐