Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

In a Spring Boot 3 or 4 application, how is Hibernate bootstrapped as the JPA provider, and where do you set Hibernate-specific properties such as hibernate.jdbc.batch_size?

When spring-boot-starter-data-jpa is on the classpath, Spring Boot's JPA auto-configuration builds a LocalContainerEntityManagerFactoryBean from the application's DataSource, with Hibernate as the provider, and scans for entities from the package of the main application class. Standard options live under spring.jpa.*, such as spring.jpa.show-sql, spring.jpa.open-in-view and spring.jpa.hibernate.ddl-auto, and any Hibernate property goes under spring.jpa.properties.*, for example spring.jpa.properties.hibernate.jdbc.batch_size=50. Hibernate 6 detects the dialect from the JDBC connection, so we rarely set it, and HibernatePropertiesCustomizer beans let code adjust properties.

Why this question is asked

Most Spring Boot developers never write JPA setup code, which is convenient until a property does not take effect, a second database is needed, or startup becomes slow. Knowing what the auto-configuration builds and where each setting goes lets us change behaviour confidently instead of copying snippets. Interviewers ask this to check that we understand what happens before the first repository call. In this answer, we will see what the starter builds, where standard and Hibernate-specific properties go, how the same setup looks without Spring, and how to adjust properties from code, and then discuss ddl-auto in production.

1What the Starter Builds for Us

spring-boot-starter-data-jpa brings Hibernate, Spring Data JPA and a connection pool (HikariCP). At startup, Spring Boot's auto-configuration notices that a DataSource and Hibernate are available and creates three main beans. The first is a LocalContainerEntityManagerFactoryBean, a Spring factory that creates the JPA EntityManagerFactory with Hibernate as the provider and our DataSource as the connection source. The second is a JpaTransactionManager, which @Transactional uses. The third is the set of Spring Data repositories, found by scanning for interfaces that extend JpaRepository and friends.

Entities are found by scanning packages. By default Boot scans the package of the class annotated with @SpringBootApplication and everything below it. If entities live elsewhere, @EntityScan("com.acme.shared.model") changes the packages. Every auto-configured bean backs off if we define our own, which is how we take control when we need to, for example for a second database. In Spring Boot 4 the auto-configuration classes moved into smaller modules with new package names, so check your version if you reference them directly; the properties stay the same.

Step throughWhat Spring Boot assembles
  1. Spring Data repositoriesinterfaces found by scanning
  2. JpaTransactionManagerused by @Transactional
  3. LocalContainerEntityManagerFactoryBeanHibernate as provider, entities scanned
  4. DataSourceHikariCP pool from spring.datasource.*
  5. Databasedialect detected from JDBC metadata

5 layers, from the top down. Step through them one at a time.

2Where Each Property Goes

Spring Boot gives first-class names to the settings most people need. Everything Hibernate understands beyond that is passed through untouched from spring.jpa.properties.*: Boot strips the prefix and hands the rest to Hibernate as it is.

Properties
# application.properties
spring.datasource.url=jdbc:postgresql://db:5432/shop
spring.jpa.show-sql=false # Boot property: log SQL to stdout
spring.jpa.open-in-view=false # Boot property: no session across the web request
spring.jpa.hibernate.ddl-auto=validate # Boot property mapped to hibernate.hbm2ddl.auto
# any Hibernate property: prefix + the Hibernate name
spring.jpa.properties.hibernate.jdbc.batch_size=50 # Hibernate sees hibernate.jdbc.batch_size=50
spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.generate_statistics=false

Notice the common mistake this rule prevents. Writing spring.jpa.hibernate.jdbc.batch_size=50 looks natural but is silently ignored, because spring.jpa.hibernate.* only knows a few Boot-defined keys such as ddl-auto and naming. The pass-through prefix is spring.jpa.properties. Also, open-in-view is on by default and Boot logs a warning at startup about it; most services should turn it off, so lazy loading cannot run database queries during view rendering.

3Why We Rarely Set the Dialect

A dialect tells Hibernate how to write SQL for a particular database: paging syntax, sequence calls, type names. Older Hibernate versions needed hibernate.dialect set explicitly. Hibernate 6 reads the database product name and version from the JDBC connection's metadata at startup and picks the matching dialect and version-specific features itself. Setting the dialect by hand, for example to an old PostgreSQL dialect class, can even make Hibernate ignore features of the newer server, so we leave it out unless we have a specific reason, such as starting without a database connection.

4The Same Setup Without Spring

Outside Spring, standard JPA bootstraps from a META-INF/persistence.xml file that names the persistence unit, its classes and properties, and the code calls Persistence.createEntityManagerFactory with the unit name. Hibernate also has its own native bootstrap, which gives a SessionFactory directly.

Java
// JPA standard bootstrap, reading META-INF/persistence.xml
EntityManagerFactory emf = Persistence.createEntityManagerFactory("shop");
// Hibernate native bootstrap
StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.applySetting("hibernate.connection.url", "jdbc:postgresql://db:5432/shop")
.applySetting("hibernate.jdbc.batch_size", 50)
.build();
SessionFactory sf = new MetadataSources(registry)
.addAnnotatedClass(Order.class)
.buildMetadata()
.buildSessionFactory(); // SessionFactory also implements EntityManagerFactory

Seeing these helps explain what Boot does: the LocalContainerEntityManagerFactoryBean plays the role of persistence.xml, using Spring's DataSource and package scanning instead of a file.

5Adjusting Properties From Code

Sometimes a property value must be computed, or a library wants to contribute a setting without asking every application to add a line. Boot calls every HibernatePropertiesCustomizer bean with the final property map before the EntityManagerFactory is built.

Java
@Bean
HibernatePropertiesCustomizer jdbcBatching() {
return props -> {
props.put("hibernate.jdbc.batch_size", 50);
props.put("hibernate.session_factory.statement_inspector", new TenantCommentInspector());
};
}
// the map Hibernate receives now contains both entries

This is also the place for values that are objects rather than strings, such as an interceptor or a statement inspector instance.

6Follow-up questions

Why should ddl-auto be validate or none in production?

Because update and create let Hibernate change the schema on startup, guessing from the entities. It never drops columns, cannot rename them, may choose types or constraints we did not intend, and runs unreviewed DDL against production with application credentials. Schema changes should be versioned migrations with Flyway or Liquibase, reviewed and tested. validate checks that the mapping matches the schema and fails fast; none skips that check, which some teams prefer when migration tests already cover it and startup time matters.

Why did my spring.jpa.hibernate.jdbc.batch_size setting have no effect?

Because only spring.jpa.properties.* is passed through to Hibernate. The correct key is spring.jpa.properties.hibernate.jdbc.batch_size.

How do I see which properties Hibernate actually received?

Hibernate logs its settings at debug level during startup, and the Actuator configprops endpoint shows the bound spring.jpa values. A HibernatePropertiesCustomizer that logs the map is another quick check.

7Conclusion

In this answer, we saw that the JPA starter auto-configures a LocalContainerEntityManagerFactoryBean from the DataSource with Hibernate as provider, plus a JpaTransactionManager and the repositories, scanning entities from the application package. Standard options live under spring.jpa.*, Hibernate properties go under spring.jpa.properties.*, the dialect is detected from JDBC metadata, and HibernatePropertiesCustomizer beans adjust properties from code. Without Spring, the same happens through persistence.xml or Hibernate's native bootstrap, and in production ddl-auto should be validate or none.

What to say in the interviewAbout 80 seconds aloud

Open with

With spring-boot-starter-data-jpa on the classpath, Spring Boot's JPA auto-configuration takes the DataSource it built from spring.datasource and creates a LocalContainerEntityManagerFactoryBean with Hibernate as the provider. It scans entities from the package of the main application class downwards, unless I use EntityScan, and it also creates a JpaTransactionManager and the Spring Data repositories.

Then, if they want more

All of these back off if I define my own beans. For configuration, the common settings have Boot names under spring.jpa: show-sql, open-in-view, which I usually turn off, and hibernate.ddl-auto. Anything Hibernate-specific goes under spring.jpa.properties and is passed through as is, so batch size is spring.jpa.properties.hibernate.jdbc.batch_size equals 50. A common mistake is writing spring.jpa.hibernate.jdbc.batch_size, which is silently ignored.

I normally do not set the dialect, because Hibernate 6 detects the database and version from JDBC metadata. If I need to set properties from code, for example an interceptor instance or a computed value, I declare a HibernatePropertiesCustomizer bean. Without Spring, the same thing happens through persistence.xml and Persistence.createEntityManagerFactory, or Hibernate's native bootstrap with StandardServiceRegistryBuilder and MetadataSources.

And in production I keep ddl-auto on validate or none, because schema changes should be reviewed migrations with Flyway or Liquibase, not something Hibernate guesses at startup.

About this answer

Last updated
12 November 2026
Versions it names
Hibernate 6, Spring Boot 4
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "In a Spring Boot 3 or 4 application, how is Hibernate bootstrapped as the JPA provider...": https://scrivio-interview-library.netlify.app/databases/jpa-fundamentals/49d3c12ae2/