0% found this document useful (0 votes)
30 views

Steps To Use Spring Data JPA

This document provides an overview of how to use Spring Data JPA repositories. It explains that Spring Data Commons and Spring Data JPA provide repository interfaces that support CRUD operations. It outlines the three main steps to create and use a Spring Data JPA repository: 1) Create a repository interface extending JpaRepository, 2) Add custom query methods, and 3) Inject and use the repository in another component. The repository implementation is provided automatically by Spring Data JPA.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Steps To Use Spring Data JPA

This document provides an overview of how to use Spring Data JPA repositories. It explains that Spring Data Commons and Spring Data JPA provide repository interfaces that support CRUD operations. It outlines the three main steps to create and use a Spring Data JPA repository: 1) Create a repository interface extending JpaRepository, 2) Add custom query methods, and 3) Inject and use the repository in another component. The repository implementation is provided automatically by Spring Data JPA.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

How to use Spring Data

JPA Repository
By Ramesh Fadatare (Java Guides)
Spring Data Commons and Spring Data JPA
Repository Interfaces
Spring Data

Spring Data
Spring Data
Commons

Spring Data Spring Data Spring Data Spring Data


……
LDAP MongoDB JPA JDBC

support for JPA-based data access layers


JpaRepository

Entity Type Primary Key

ndAll()

CRUD ndById()
Operations save()
deleteById()
------
fi
fi
JpaRepository Implementation
SimpleJpaRepository implementation class
provides implementation for methods

JpaRepository
Interface
Steps to create and use Spring Data
JPA Repository
1. Create a repository interface and extend to JpaRepository interfac

2. Add custom query methods to the created repository interface (if we


need them)

3. Inject the repository interface to another component and use the


implementation that is provided automatically by Spring Data Jpa

1. Create a repository interface and


extend to JpaRepository interfac

Primary
JPA Entity
Key

2. Add custom query methods to the created


repository interface (if we need them)

Query method or
nder method
fi
3. Using Repository interface in our projec

Our repository

Calling our repository save() method

Calling our repository saveAll() method

Calling our repository ndAll() method


fi
t

Minimised boilerplate code


Before Spring Data JPA After Spring Data JPA

1 Fil
3 lines of code

No need for implementation Class

2 File
30+ lines of code
e

You might also like