#JpaRepository #CRUDRepository #PagingAndSortingRepository
► Difference between CrudRepository and JpaRepository and PagingAndSortingRepository interfaces in Spring Data JPA
► SUBSCRIBE & LIKE!!
► Official Email Id: techtalk.debu@gmail.com
► Download the sample java microservice application :
github.com/admindebu/In-Memor...
► Follow on Facebook: / techtalkdebu
► Follow on LinkedIn: / debu-paul
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
► Here is our amazing playlist for Core Java, Spring MVC/Boot, Git and Micro service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Core Java :: • Exception in Java deta...
2. Spring MVC & Spring Boot :: • Quick Start Spring Boo...
3. Micro Service :: • Micro Service - Monoli...
4. Git/GitHub :: • VCS - What is GitHub a...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Watch my "Most Watched Videos"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
► HTTPS & HTTPS protocol :: • What is HTTP Protocol ...
Playlist : • Core Java Interview Qu... Tutorial for beginners with examples, Interview Questions and Concepts.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Important Notes Related to Spring Data JPA Repository
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
► JpaRepository extends PagingAndSortingRepository which in turn extends CrudRepository.
Their main functions are:
• CrudRepository mainly provides CRUD functions.
• PagingAndSortingRepository provides methods to do pagination and sorting records.
• JpaRepository provides some JPA-related methods such as flushing the persistence context and deleting records in a batch.
Because of the inheritance mentioned above, JpaRepository will have all the functions of CrudRepository and PagingAndSortingRepository. So if you don't need the repository to have the functions provided by JpaRepository and PagingAndSortingRepository , use CrudRepository.
====================================
► CrudRepository - extends Repository
====================================
save(…) - save an Iterable of entities. Here, we can pass multiple objects to save them in a batch
saveAll(…) - Save all the entities
findById (…) - get a single entity based on passed primary key value
findAll() - get an Iterable of all available entities in database
findAllById(…) - get an Iterable of all available entities in database by matching criteria
count() - return the count of total entities in a table
delete(…) - delete an entity based on the passed object
deleteById(…) - delete an entity based on unique id value
deleteAll(…) - delete all entity from the table
existsById(…) - verify if an entity exists based on the passed primary key value
================================================
► PagingAndSortingRepository - extedns CrudRepository
================================================
In addition, CRUDRepository method below two additions are there
Iterable(T) findAll(Sort sort);
Page(T) findAll(Pageable pageable);
This interface provides a method findAll(Pageable pageable), which is the key to implementing Pagination
Example: I want to sort the record by name ascending order and each page should contain 10 records.
Sort sort = new Sort(new Sort.Order(Direction.ASC, "name"));
Pageable pageable = new PageRequest(0, 10, sort);
================================================
► JpaRepository - extends PagingAndSortingRepository
================================================
In addition, CRUDRepository method + PagingAndSortingRepository method + below methods
findOne (…) - get a single entity based on passed primary key value
flush() - flush all pending task to the database
saveAndFlush(…) - save the entity and flush changes immediately
deleteInBatch(…) - delete an Iterable of entities. Here, we can pass multiple objects to delete them in a batch
deleteAllInBatch() - delete all entities.
Regards,
Debu Paul
7 май 2020