Spring Boot/Spring Data Jpa:spring.jpa.properties.hibernate.generate_statistics及相关Hibernate属性的Java代码读取位置咨询
spring.jpa.properties.hibernate.* Properties Hey there! Since you're already digging into Spring Boot's property handling (great job tracking down DataSourceProperties!), let's figure out where those Hibernate-specific properties fit in.
First, the key difference with spring.jpa.properties.*
Unlike spring.datasource.driverClassName which maps directly to a field in a Spring Boot properties class, properties under spring.jpa.properties.* are dynamic, pass-through properties meant for Hibernate itself. Spring Boot doesn't create individual Java fields for every possible Hibernate property—instead, it collects all of them into a map and hands them off to Hibernate's configuration system.
Where to find the Spring Boot code that handles these
Start with
JpaProperties
Look for the classorg.springframework.boot.autoconfigure.orm.jpa.JpaProperties. This is the main class that binds allspring.jpa.*properties. Inside it, you'll find a field calledproperties(aMap<String, Object>) that captures every property underspring.jpa.properties.*. Check thegetProperties()method to see how these are exposed.Track how they reach Hibernate
Next, head toorg.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration(the base class for JPA auto-configurations). In itsgetVendorProperties()method, you'll see it pulls the properties fromJpaPropertiesand merges them into the vendor-specific configuration (for Hibernate, this feeds into theHibernateSettingsorConfigurationobject).If you're using a newer Spring Boot version, you might also look at
EntityManagerFactoryBuilder—it uses these properties to build the HibernateSessionFactoryunder the hood.
Why you didn't find direct fields in the ORM path
Since Hibernate has hundreds of possible configuration properties, Spring Boot doesn't hardcode each one into a Java class. Instead, it uses the spring.jpa.properties.* prefix as a catch-all. Hibernate itself will parse these properties from the map and apply them—for example:
spring.jpa.properties.hibernate.cache.use_query_cachegets translated to Hibernate'shibernate.cache.use_query_cachesetting, which controls query caching.spring.jpa.properties.hibernate.generate_statisticsmaps to Hibernate'shibernate.generate_statistics, enabling stats collection.
A quick way to verify
Set a breakpoint in JpaProperties.getProperties() when your app starts. You'll see your two target properties in the returned map, confirming Spring Boot is picking them up. Then follow the trail to JpaBaseConfiguration to see how they're passed to Hibernate's configuration machinery.
内容的提问来源于stack exchange,提问作者samshers

