What is the difference between JpaRepository and CrudRepository, and when would you use CrudRepository?

CrudRepository and JpaRepository are Spring Data repository interfaces used for database operations. CrudRepository provides fundamental CRUD functionality, while JpaRepository extends it and offers additional JPA-specific capabilities such as pagination, sorting, batch operations, and persistence context management.

Key Points

Hierarchy

Repository

↓

CrudRepository

↓

PagingAndSortingRepository

↓

JpaRepository

Common Methods

CrudRepository

Additional JpaRepository Methods

Example

Consider a small inventory application that only needs to add, update, retrieve, and delete products. In this case, CrudRepository is sufficient because advanced features such as pagination and batch processing are not required.

import org.springframework.data.repository.CrudRepository;

public interface ProductRepository
        extends CrudRepository<Product, Long> {

}

When to Use CrudRepository

When to Use JpaRepository

Interview Tip

A concise interview answer is: CrudRepository provides basic CRUD operations and is suitable for simple applications that only need standard database interactions. JpaRepository extends CrudRepository and adds advanced JPA features such as pagination, sorting, flushing, and batch processing. In most enterprise applications, JpaRepository is preferred, while CrudRepository is useful for lightweight applications with simple CRUD requirements.

Last updated: 11 November 2026

Previous question: What is the difference between @Component and @Service? Are they interchangeable?

Next question: What is the difference between @Qualifier and @Primary, and when is each used?

More Spring Framework - Level II interview questions

All Spring Framework - Level II questions