CrudRepository vs JpaRepository vs PagingAndSortingRepository
Fast recall
Quick revision
Core answer
Whether you know the repository hierarchy and that JpaRepository transitively includes paging/sorting plus JPA batch methods
Picking PagingAndSortingRepository for pagination without realizing JpaRepository already includes it plus batch methods and List returns
Recommend JpaRepository as the default and explain deleteAllInBatch() vs deleteAll() for bulk performance
Interview-ready guide
Interview answer
These interfaces are capabilities, not a simple three-step inheritance chain in current Spring Data. CrudRepository exposes generic CRUD. PagingAndSortingRepository independently exposes sorted and paged findAll methods, so a store-neutral interface that wants both now extends both. JpaRepository is designed for JPA and combines list-returning CRUD and paging interfaces with operations such as flush, saveAndFlush, and batch deletion. In a normal JPA application, extending JpaRepository is convenient; a smaller custom base interface is reasonable when the application intentionally wants to expose fewer operations.
CrudRepository vs JpaRepository vs PagingAndSortingRepository
Direct Answer
CrudRepository provides basic save, find, count, and delete operations. PagingAndSortingRepository adds sorting and paging operations, but since Spring Data 3 it no longer extends CrudRepository, so a custom repository that needs both must extend both. JpaRepository is the JPA-specific convenience interface and already combines list-based CRUD, paging, sorting, and JPA operations such as flush and batch deletes.
Common Mistakes & Pitfalls
Picking PagingAndSortingRepository for pagination without realizing JpaRepository already includes it plus batch methods and List returns
Check your understanding
Answer these without looking back at the article.
- What does JpaRepository add over CrudRepository?
- How does findAll(Pageable) work?
- What is getReferenceById() vs findById()?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.