The spring-boot-starter-data-jpa dependency gives a Spring Boot application everything it needs to store and query relational data through JPA: Spring Data JPA repositories, Hibernate as the JPA provider, Spring transaction management and an auto-configured EntityManagerFactory. You add the starter and a JDBC driver, point Spring Boot at a database, and you can define repository interfaces without writing implementations.
It is the standard starting point for relational persistence in Spring Boot, and it works with PostgreSQL, MySQL, MariaDB, H2 and any other database that has a Hibernate dialect.
The starter bundles these libraries:
| Library | Role |
|---|---|
| Spring Data JPA | Repository abstraction, derived queries, paging |
| Hibernate ORM | The JPA implementation that maps entities to tables |
| Jakarta Persistence API | The jakarta.persistence annotations such as @Entity |
| Spring ORM and Spring transactions | @Transactional and JpaTransactionManager |
spring-boot-starter-jdbc (HikariCP) | The connection pool and DataSource support |
Spring Boot 3 and later use the jakarta.persistence namespace and require Java 17 or newer. Older Boot 2.x applications use javax.persistence, so imports change when you upgrade.
The starter does not include a database driver, so add one that matches your database.
Then configure the connection:
Spring Boot builds a pooled DataSource from these properties, creates the EntityManagerFactory, and registers a JpaTransactionManager. Hibernate detects the dialect from the JDBC URL, so you normally do not set it.
An entity is a class mapped to a table. A repository is an interface that extends JpaRepository; Spring generates the implementation at startup.
Inherited methods such as save, findById, findAll, deleteById and count need no code. Method names like findByNameContainingIgnoreCase are parsed into queries, and @Query accepts JPQL for anything more specific. Boot scans for entities and repositories starting from the package of your @SpringBootApplication class.
Annotate service methods with @Transactional so that several repository calls commit or roll back together.
By default Spring Boot enables spring.jpa.open-in-view, which keeps the persistence context open during web request rendering and logs a warning at startup. It can hide lazy-loading queries in the view layer and holds a connection longer, so many teams set it to false and fetch what a response needs inside the service.
spring.jpa.hibernate.ddl-auto accepts none, validate, update, create and create-drop. Boot defaults to create-drop for embedded databases and none otherwise. Do not rely on update in production; it cannot handle renames or data migrations safely. Use Flyway or Liquibase for versioned migrations (both have starters) and keep ddl-auto at validate or none.
Common problems to watch for:
join fetch, @EntityGraph or DTO projections.LazyInitializationException: it appears when you touch a lazy association after the transaction ended; load it inside the transaction.Failed to determine a suitable driver class means no driver is on the runtime classpath or the URL is missing.No. Add the driver for your database yourself. The only exception is an embedded database such as H2, which you add as its own dependency for local development and tests.
Hibernate is the JPA implementation that maps objects to tables and runs SQL. Spring Data JPA sits on top and generates repository implementations, so you write interfaces rather than DAO classes.
Avoid it outside of throwaway prototypes. Use a migration tool such as Flyway or Liquibase and set ddl-auto to validate.
Yes. The starter includes JDBC support, so you can inject JdbcClient or JdbcTemplate for hand-written SQL while sharing the same DataSource and transactions.
spring-boot-starter-data-jpa combines Spring Data JPA, Hibernate, the Jakarta Persistence API and transaction support, and Spring Boot auto-configures the DataSource, EntityManagerFactory and transaction manager from your properties. Add a driver, define entities and repository interfaces, manage the schema with migrations, and keep an eye on lazy loading and open-in-view to avoid common performance traps.