What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?

kseeker picture kseeker · Dec 23, 2012 · Viewed 279k times · Source

What is the difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?

When I see the examples on the web, I see them there used kind of interchangeably.

What is the difference between them?

Why would you want to use one over the other?

Answer

Ken Chan picture Ken Chan · Dec 24, 2012

JpaRepository extends PagingAndSortingRepository which in turn extends CrudRepository.

Their main functions are:

Because of the inheritance mentioned above, JpaRepository will have all the functions of CrudRepository and PagingAndSortingRepository. So if you don't need the repository to have the functions provided by JpaRepository and PagingAndSortingRepository , use CrudRepository.