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).

Spring Data JPA Tutorial

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 sources web application.
  • Spring Data Java 8 Support - Spring Data now supports core Java 8 features – such as Optional, Stream API and CompletableFuture. In this quick article, we’ll go through some examples of how we can use these with the framework.
  • Spring Data Annotations - In this tutorial, we’ll see the most common annotations of the Spring Data, Spring Data JPA, and Spring Data MongoDB projects.
  • 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 main methods of 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 basic flow at the time of accessing the database using Spring Data JPA is shown below.

Useful Resources and Links

This section showcases useful material created by other developers. If you have written a blog post or recorded a video about Spring Data JPA, and want to include it to this section, do comment and I will check it out. If I think that it is useful, I will add it to this section.

Reference Manuals and Official Guides

Blog Posts/Articles

Top J2EE Tutorials


Comments

Post a Comment