Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

14/04/2024, 22:02 Springboot snippets I— Crud vs JPA Repository | by Nikita Mehra | Medium

Open in app

Search

Get unlimited access to the best of Medium for less than $1/week. Become a member

Springboot snippets I— Crud vs JPA Repository


Nikita Mehra · Follow
1 min read · Apr 8, 2022

Listen Share More

Both Crud and JPA Repository are interfaces of Spring data library. The advantage of using Spring data library is that it provides
boilerplate code to access your data layer.

Crud Repository: It is the base interface and extends the Repository interface. It contains methods for Create, Read, Update and
Delete operations. For example: save(), findById()

@Repository
public interface MyPlaylistDAO extends CrudRepository {
Book Event findById(@Param("id") Integer id);
}

JPA Repository: It extends PagingAndSorting Repository which in turn extends CrudRepository. It contains methods for all CRUD
operations and also for implementing pagination. In addition to that it provides methods for batch operations like deleting
records in batch and flushing data directly to a database. For example: saveAllAndFlush(), deleteInBatch(), findAll(Pageable
pageable)

@Repository
public interface MyPlaylistDAO extends JpaRepository {
Book findByArtist(@Param("id") Integer id);
}

Resources:

1. https://www.baeldung.com/spring-data-repositories

2. https://www.baeldung.com/the-persistence-layer-with-spring-data-jpa

3. https://www.baeldung.com/spring-data-jpa-pagination-sorting

Spring Boot Java Database Engineering Technology

More from the list: "Reading list"


Curated by Akankshaojha

https://medium.com/@mehra.nikita3006/springboot-snippets-i-crud-vs-jpa-repository-b074ad66c536 1/7

You might also like