This is most common interview questions asked about Spring data.

In SpringBoot, you may get encounter when to use CrudRepository and JpaRepository. In this post, we will cover the list of interface provided by Spring Boot Data;

The below are order of interfaces

CrudRepository, PagingAndSortingRepository and JpaRepository are both interfaces provided by Spring Data that are used to simplify the implementation of data access operations in a Spring application.

CrudRepository is a basic interface for CRUD (Create, Read, Update, Delete) operations on a repository. It provides a set of methods for performing CRUD operations on a repository, such as save, findOne, findAll, delete, etc.

JpaRepository is a more specialized interface that extends CrudRepository and adds additional methods for working with JPA (Java Persistence API) persistence contexts. JPA is a Java specification for accessing, persisting, and managing data between Java objects/classes and a relational database. It provides a set of additional methods for working with JPA-specific features, such as pagination and sorting.

PagingAndSortingRepository is another Spring Data repository interface, which builds upon the CrudRepository interface and adds support for pagination and sorting of data.

In summary, CrudRepository is a general interface for CRUD operations, while JpaRepository is a specialized interface for working with JPA persistence contexts that also provides CRUD operations. So, if you’re working with JPA you should use JpaRepository instead of CrudRepository