spring-data-jpa
spring-boot-starter-data-jpa
spring framework
JPA
Java development

Difference between spring-data-jpa and spring-boot-starter-data-jpa

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

spring-data-jpa and spring-boot-starter-data-jpa are closely related, but they solve different dependency-management problems. The first is the core library that gives you repository support on top of JPA. The second is a Spring Boot starter that pulls that library in together with the pieces a Boot application usually needs for persistence.

What spring-data-jpa Actually Is

spring-data-jpa is the focused Spring Data module. It adds higher-level repository abstractions on top of the JPA specification.

It provides features such as:

  • 'JpaRepository and related repository interfaces'
  • derived query methods such as findByEmail
  • '@Query support for JPQL and native SQL'
  • paging and sorting support

Example dependency:

xml
1<dependency>
2  <groupId>org.springframework.data</groupId>
3  <artifactId>spring-data-jpa</artifactId>
4</dependency>

By itself, that dependency is not a complete persistence runtime. You still need a JPA provider, transaction setup, a datasource, and a JDBC driver.

What the Boot Starter Adds

spring-boot-starter-data-jpa is a convenience bundle for Spring Boot applications. It includes spring-data-jpa, but also pulls in the supporting infrastructure that Boot expects to auto-configure.

Typical starter usage:

xml
1<dependency>
2  <groupId>org.springframework.boot</groupId>
3  <artifactId>spring-boot-starter-data-jpa</artifactId>
4</dependency>
5
6<dependency>
7  <groupId>com.h2database</groupId>
8  <artifactId>h2</artifactId>
9  <scope>runtime</scope>
10</dependency>

The Boot starter is not a different ORM. It is a curated dependency set plus auto-configuration support.

Manual Setup Versus Auto-Configuration

The practical difference is who assembles the persistence stack.

With spring-data-jpa directly, you wire most pieces yourself:

  • datasource
  • entity manager factory
  • transaction manager
  • repository scanning
  • JPA provider settings

With the Boot starter, Boot auto-configures much of that when it detects the right dependencies and properties.

That is why a Boot application often needs only a few properties:

properties
1spring.datasource.url=jdbc:h2:mem:testdb
2spring.datasource.driver-class-name=org.h2.Driver
3spring.jpa.hibernate.ddl-auto=update
4spring.jpa.show-sql=true

Example Repository Code

The repository code itself looks the same because the repository API comes from Spring Data JPA, not from the starter.

java
1package com.example.demo.user;
2
3import jakarta.persistence.Entity;
4import jakarta.persistence.GeneratedValue;
5import jakarta.persistence.GenerationType;
6import jakarta.persistence.Id;
7
8@Entity
9public class User {
10    @Id
11    @GeneratedValue(strategy = GenerationType.IDENTITY)
12    private Long id;
13
14    private String email;
15
16    protected User() {}
17
18    public User(String email) {
19        this.email = email;
20    }
21
22    public Long getId() {
23        return id;
24    }
25
26    public String getEmail() {
27        return email;
28    }
29}
java
1package com.example.demo.user;
2
3import java.util.Optional;
4import org.springframework.data.jpa.repository.JpaRepository;
5
6public interface UserRepository extends JpaRepository<User, Long> {
7    Optional<User> findByEmail(String email);
8}

What changes is how much wiring you do around that repository.

When to Use Each One

Use spring-boot-starter-data-jpa when:

  • you are building a normal Spring Boot application
  • you want convention-based setup
  • you want Boot to assemble the common persistence stack

Use spring-data-jpa directly when:

  • you are not using Spring Boot
  • you need unusually tight dependency control
  • you already have a custom infrastructure layer

For most Boot projects, using the starter is the simpler and more maintainable choice.

A Simple Mental Model

Think of it this way:

  • 'spring-data-jpa gives you repository functionality'
  • 'spring-boot-starter-data-jpa gives you repository functionality plus a Boot-friendly way to run it'

That distinction keeps dependency decisions clear and avoids treating the starter like a competing technology.

Common Pitfalls

  • Thinking the starter is a different persistence framework. Fix: remember that the starter includes spring-data-jpa; it does not replace it.
  • Forgetting the database driver dependency. Fix: add the correct JDBC driver for PostgreSQL, MySQL, H2, or whichever database you use.
  • Using spring-data-jpa directly in a Boot app without a reason. Fix: prefer the starter unless you have a concrete reason to assemble dependencies manually.
  • Expecting Boot-style auto-configuration in a non-Boot application. Fix: configure datasource, transactions, and JPA infrastructure explicitly when not using Boot.
  • Blaming repository code for startup failures caused by datasource configuration. Fix: separate repository API concerns from runtime wiring concerns when debugging.

Summary

  • 'spring-data-jpa is the core library that provides repository support on top of JPA.'
  • 'spring-boot-starter-data-jpa is a Boot starter that includes that library and common supporting dependencies.'
  • The repository API is the same either way; the setup experience is different.
  • Boot applications usually should use the starter.
  • Non-Boot or highly customized applications may prefer the library directly.

Course illustration
Course illustration

All Rights Reserved.