It seems that to collect Hibernate statistics metric is not working in spring boot 2.5 version.

When I enable following options spring.jpa.properties.hibernate.generate_statistics=true.

In case of 2.4, data is collected, but when I change to 2.5, to collect statistics metric is not working.

I found the reason https://github.com/spring-projects/spring-boot/commit/7c5e0505d84f2087568e54723b44d8227d2f839b https://github.com/spring-projects/spring-boot/commit/eb406867eaa36032946d59851240e72d726974d0 It seems to have something to do with that commits.

I have checked to validate the HibernateMetrics class with ConditionalOnClass.

And in the above commit, the verification target was changed to io.micrometer.core.instrument.binder.jpa.HibernateMetrics of micrometer-core -> org.hibernate.stat.HibernateMetrics of hibernate-core.

I have checked org.hibernate.stat.HibernateMetrics class seems to have been added since hibernate-5.5.0. https://github.com/hibernate/hibernate-orm/commit/33ac4174c731334fb46bd3c797ebb6d47abdb959

However, in the case of spring-boot-starter-data-jpa v2.5.14, it has org.hibernate:hibernate-core:5.4.33, so it was not possible to track hibernate statistics metric. https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa/2.5.14

If this is correct, spring-boot-starter-actuator v2.5.14 has io.micrometer:micrometer-core:1.7.12. and io.micrometer:micrometer-core:1.7.12 still has io.micrometer.core.instrument.binder.jpa.HibernateMetrics

So I think it could be working, if put io.micrometer.core.instrument.binder.jpa.HibernateMetrics back in the 2.5.x branch. https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator/2.5.14

If what I said is correct, can I send you a PR?

Thanks :)

Comment From: wilkinsona

org.hibernate.stat.HibernateMetrics class seems to have been added since hibernate-5.5.0

HibernateMetrics exists in Hibernate 5.4: https://github.com/hibernate/hibernate-orm/blob/5.4/hibernate-micrometer/src/main/java/org/hibernate/stat/HibernateMetrics.java. As Spring Boot 2.5.x compiles against Hibernate 5.4.x, we would not have been able to build Spring Boot if the class wasn't present.

If what I said is correct, can I send you a PR?

Thanks for the offer but I don't think this is the right way to fix the problem. Also, please note that Spring Bot 2.5.x is no longer supported. If you can reproduce the problem with Spring Boot 2.6.x or 2.7.x and you would like us to investigate, please provide a minimal sample and we can take a look.

Comment From: koo-taejin

Thasnks for your answer. I will close this issue. :)