Professional Documents
Culture Documents
Springboot Snippets I - Crud Vs JPA Repository - by Nikita Mehra - Medium
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
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
https://medium.com/@mehra.nikita3006/springboot-snippets-i-crud-vs-jpa-repository-b074ad66c536 1/7