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.
That’s all about Difference between Repository and CrudRepository in Spring Data JPA.
You may like.
- Difference between CrudRepository and JpaRepository in Spring Data JPA.
- Difference between Iterator and ListIterator in Java.
- Difference between Iteration and Enumeration in java.
- Difference between HashSet and TreeSet in java.
- Difference between List and Set in Java.
- Difference between ArrayList and LinkedList in java.
Other Spring Data JPA and Hibernate post.
- @Version Annotation Example In Hibernate.
- Hibernate Validator Constraints Example Using Spring Boot.
- @Temporal Annotation Example In Hibernate/Jpa Using Spring Boot.
- Hibernate Table Per Concrete Class Spring Boot.
- Hibernate Table Per Subclass Inheritance Spring Boot.
- Hibernate Single Table Inheritance using Spring Boot.
- One To One Mapping Annotation Example in Hibernate/JPA using Spring Boot and Oracle.
- One To One Bidirectional Mapping Example In Hibernate/JPA Using Spring Boot and Oracle.
- One To Many Mapping Annotation Example In Hibernate/JPA Using Spring Boot And Oracle.
- Many To One Unidirectional Mapping In Hibernate/JPA Annotation Example Using Spring Boot and Oracle.
- One To Many Bidirectional Mapping In Hibernate/JPA Annotation Example Using Spring Boot and Oracle.
- Many To Many Mapping Annotation Example In Hibernate/JPA Using Spring Boot And
Spring Data JPA Docs.
Summary – We have seen Difference Difference between Repository and CrudRepository in Spring Data JPA.