Question

I have a small sample app here

https://github.com/jimbasilio/SpringBoot

that creates some simple data in the database and some other things I'm working on to kick the tires on spring boot (side note: so far i LOVE spring boot!!). If you clone the git repo you can visit the url:

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

and it'll load from the database and write the hibernate statistics to the console.

I do have a problem though, with or without configuring hibernate statistics via the application.properties file:

hibernate.generate_statistics=true

when i write the hibernate statistics out i get nothing useful. I'm fetching the statistics via:

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

my SECOND log message (after flush) is below. You can see it doesn't even register sessions being opened. I'm using spring boot 1.0.1.RELEASE.

pom.xml

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

log file:

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
Was it helpful?

Solution 2

I think Hibernate is just not reading your config.

According to Hibernate's Reference Manual you're supposed to put Hibernate configuration on hibernate.properties or hibernate.cfg.xml. If those didn't work you might also want to try the programmatic config.

OTHER TIPS

Use spring.jpa.properties.hibernate.generate_statistics=true instead-of
hibernate.generate_statistics=true

I also have the same issue in my spring boot application. All the tutorials and threads I found told me to use spring.jpa.properties.hibernate.generate_statistics=true but it was not working. Then I added hibernate.properties file to the resource folder and inside the file add hibernate.generate_statistics=true Then I restart my spring boot app and it works like a charm.

So I guess there is some bug/issue in some specific spring boot version(I was using 2.2.13) where the generate_statistics would not be taken by hibernate from spring.jpa.properties. Btw, all the other properties like format_sql is working by setting up in spring.jpa.properties

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top