Spring Data JPA Tutorial

Spring Data is a part of Spring Framework. The goal of Spring Data repository abstraction is to significantly reduce the amount of boilerplate code required to implement data access layers for various persistence stores.

Spring Data JPA is not a JPA provider. It is a library/framework that adds an extra layer of abstraction on the top of our JPA provider (like Hibernate).

Latest Published Tutorials

  • Spring Data REST Tutorial - In this tutorial, we will learn how to use the Spring Data REST module to create REST endpoints.

Spring Data JPA Tutorials and Examples

This tutorial describes how you can create JPA repositories without writing any boilerplate code, and it consists of the following blog posts.
  • Spring Data JPA Tutorial - Getting Started - This article provides a quick introduction to Spring Data JPA. It also describes all the important interfaces of Spring data commons and Spring Data JPA - Repository, CrudRepository, PagingAndSortingRepository, QueryDslPredicateExecutor, JpaRepository, JpaSpecificationExecutor
  • Spring Data JPA - Query Creation from Method Names - In this article, we will learn how we can create query methods by using the query generation from the method name strategy. We will demonstrate this with a complete end-to-end example using Spring boot.
  • Spring Data JPA - Auditing with Spring Boot 2 and MySQL Example - In this article, we will discuss how can we configure JPA to automatically persist the CreatedBy, CreatedDate, LastModifiedBy, and LastModifiedDate columns for any entity. We will create a simple Spring Boot CRUD REST APIs and we implement auditing using spring data JPA.
  • Spring Data JPA - Working with Multiple Datasources using Spring Boot -  In this article, we will learn how to configure multiple data sources and connect to multiple databases in a typical Spring Boot web application. We will use Spring Boot, JPA, Hibernate 5, Thymeleaf, and H2 database to build a simple Spring Boot multiple data source web application.
  • Spring @Repository Annotation - In this quick article, we will discuss how to use @Repository annotation in Spring-based applications. DAO or Repository classes usually represent the database access layer in an application and should be annotated with @Repository.

API Mapping of Spring Data JPA and JPA

The SimpleJpaRepository class provides the default implementation of a Repository interface. SimpleJpaRepository class internally uses JPA EntityManager to map its methods with JPA EntityManager interface methods.

It is better to know which JPA EntityManager method is being called by methods of Repository interface (SimpleJpaRepository class ) of Spring Data JPA.

The JPA methods called by the main methods of the Repository interface of Spring Data JPA are shown below. 

Basic Spring Data JPA Flow

Once you completed reading above all articles then let's understand the basic flow at the time of accessing the database using Spring Data JPA is shown below.


  1. Nice Tutorial. Really Informative.

  2. Can you post sample working Java examples for below items

    1. Spring Data Java 8 Support
    2. Spring Data Annotations

    I went thru baeldung website but it's difficult to understand. There is no working code.

    1. Yes, i will let you know once i will work on it.

  3. Could you please post examples of Native query and resultMapping using spring data jpa


Post a Comment