0
0
Spring Bootframework~5 mins

JpaRepository interface in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the JpaRepository interface in Spring Data JPA?
The JpaRepository interface provides CRUD (Create, Read, Update, Delete) operations and pagination support for JPA entities, simplifying database access without writing boilerplate code.
Click to reveal answer
intermediate
Which interface does JpaRepository extend to provide basic CRUD methods?
JpaRepository extends PagingAndSortingRepository, which itself extends CrudRepository. This means it inherits methods for CRUD and pagination.
Click to reveal answer
intermediate
Name two useful methods provided by JpaRepository that are not in CrudRepository.
1. findAll(Pageable pageable) for pagination.<br>2. flush() to synchronize the persistence context to the database immediately.
Click to reveal answer
beginner
How do you define a repository interface for an entity Book with an ID of type Long using JpaRepository?
You create an interface like this:<br>
public interface BookRepository extends JpaRepository<Book, Long> {}
This gives you all CRUD and pagination methods for Book.
Click to reveal answer
beginner
True or False: You need to write SQL queries manually when using JpaRepository for basic CRUD operations.
False. JpaRepository provides built-in methods for basic CRUD operations, so you don't need to write SQL manually for those.
Click to reveal answer
What does JpaRepository primarily provide?
ASecurity features
BOnly SQL query execution
CUI components for Spring Boot
DCRUD operations and pagination support
Which method is NOT part of JpaRepository?
AexecuteUpdate()
BfindAll()
Csave()
DdeleteById()
To add pagination support, which method would you use from JpaRepository?
AfindAll(Pageable pageable)
BfindById()
CsaveAll()
Dflush()
What type parameters does JpaRepository require?
ANo type parameters
BEntity type only
CEntity type and ID type
DID type only
Which interface is a direct parent of JpaRepository?
ACrudRepository
BPagingAndSortingRepository
CRepository
DEntityManager
Explain how JpaRepository simplifies database operations in Spring Boot applications.
Think about what common database tasks you avoid writing manually.
You got /4 concepts.
    Describe how to create a repository interface for an entity using JpaRepository and what benefits it brings.
    Focus on the interface declaration and what you get from it.
    You got /4 concepts.