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?✗ Incorrect
JpaRepository offers CRUD and pagination methods for JPA entities.Which method is NOT part of
JpaRepository?✗ Incorrect
executeUpdate() is not a method in JpaRepository. It is used in JPA Query API, not repository interfaces.To add pagination support, which method would you use from
JpaRepository?✗ Incorrect
findAll(Pageable pageable) returns a page of entities, enabling pagination.What type parameters does
JpaRepository require?✗ Incorrect
JpaRepository needs the entity class and the type of its primary key.Which interface is a direct parent of
JpaRepository?✗ Incorrect
JpaRepository extends PagingAndSortingRepository, which extends CrudRepository.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.