English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Text
CrudRepository and JpaRepository are interfaces of the Spring Data repository library. Spring Data repositories access various data layers in the persistence layer by providing some predefined finders, thus reducing boilerplate code.
We need to extend this repository in the application before we can access all the methods available in these repositories. We can also add new methods using named queries or native queries based on business requirements.
Serial number | Key | JPAR repository | Crud repository |
---|---|---|---|
1 | Hierarchy | JPA extends the crudRepository and PagingAndSorting repository | The original repository is a basic interface that acts as a marker interface. |
2 | Batch support | JPA also provides some methods related to JPA, such as batch deletion of records and directly refreshing data to the database. | It only provides CRUD functions, such as findOne, save, etc. |
3 | Pagination support | JPA repositories also extend the PagingAndSorting repository. It provides all methods that can be used for pagination. | Crud repositories do not provide methods for implementing pagination and sorting. |
4 | Use cases | JpaRepository connects your repository with JPA persistence technology, so it should be avoided. | We should use CrudRepository or PagingAndSortingRepository depending on whether you need sorting and pagination. |
@Repository public interface BookDAO extends JpaRepository { Book findByAuthor(@Param("id") Integer id); {}
@Repository public interface BookDAO extends CrudRepository { Book Event findById(@Param("id") Integer id); {}