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