Difference between Repository and CrudRepository

In this post, we will see the Difference between Repository and CrudRepository in Spring Data JPA.

Repository interface

The Repository is a top-level interface in hierarchy.

The Repository is a marker interface. It doesn’t have any method.

Repository interface has been defined as below.

@Indexed
public interface Repository<T, ID> {

}

We are looking into Difference between Repository and CrudRepository in Spring Data JPA.

CrudRepository interface.

The CrudRepository extends Repository interface. It has below methods to perform CRUD operation.

<S extends T> S save(S entity) –  See more details about save() method here.
<S extends T> Iterable<S> saveAll(Iterable<S> entities) – See more details about saveAll() method here.
Optional<T> findById(ID id) – See more details about findById() method here.
Iterable<T> findAll() – See more details about findAll() method here.
Iterable<T> findAllById(Iterable<ID> ids) – See more details about findAllById() method here.
long count() – See more details about count() method here.
void deleteById(ID id) – See more details about deleteById() method here.
void delete(T entity) – See more details about delete() method here.
void deleteAll(Iterable<? extends T> entities) – See more details about deleteAll() method here.
void deleteAll() – See more details about deleteAll() method here.

Let’s see Repository hierarchy.

Difference between CrudRepository and JpaRepository in Spring Data JPA

That’s all about Difference between Repository and CrudRepository in Spring Data JPA.


You may like.


 

Other Spring Data JPA and Hibernate post.

Spring Data JPA Docs.

Summary – We have seen Difference Difference between Repository and CrudRepository in Spring Data JPA.