Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate statistics in spring boot not working?

Tags:

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 
like image 858
JimB Avatar asked Apr 29 '14 01:04

JimB


People also ask

How do I enable Hibernate statistics?

If you enable Hibernate statistics by setting the property hibernate. generate_statistics to true, Hibernate will expose a number of useful metrics. The page "Statistics" is used to expose these metrics.

Does Spring Data JPA use Hibernate internally?

By default, Spring uses Hibernate as the default JPA vendor. you can see hibernate related dependency in dependency hierarchy under the pom. xml, this will resolve all dependencies of your project.

Why use Hibernate with Spring Data JPA?

Conclusion. Hibernate is a JPA provider and ORM that maps Java objects to relational database tables. Spring Data JPA is an abstraction that makes working with the JPA provider less verbose. Using Spring Data JPA you can eliminate a lot of the boilerplate code involved in managing a JPA provider like Hibernate.


1 Answers

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

like image 107
Rashad Saif Avatar answered Oct 07 '22 22:10

Rashad Saif