Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you enable hibernate.generate_statistics with Spring Boot?

I'm using Spring Boot with Java config. How do I enable hibernate.generate_statistics? I already do have:

logging.level.org.hibernate.stat: INFO

So I tried adding the following config props, and none of these worked:

spring.jpa.hibernate.properties.generate_statistics: true

spring.jpa.hibernate.properties.generate-statistics: true

spring.jpa.hibernate.generate-statistics: true

spring.jpa.hibernate.generate_statistics: true

hibernate.generate-statistics: true

hibernate.generate_statistics: true

The only thing that did work was adding:

-Dhibernate.generate_statistics=true

to the command line. However, for my use case, I prefer to configure this within the Java application itself or properties file in its JAR, not externally on the command line.

Another solution I see is I can also add a "hibernate.properties" file to my classpath, with the contents

hibernate.generate_statistics=true

And that does indeed work. But is it ideal?

like image 238
lammy Avatar asked Nov 03 '16 18:11

lammy


1 Answers

According to the documentation, to set a native property on the JPA provider, you can use:

spring.jpa.properties.*= ...

So for hibernate.generate_statistics, use:

spring.jpa.properties.hibernate.generate_statistics=true
like image 51
Ortomala Lokni Avatar answered Oct 07 '22 01:10

Ortomala Lokni