- Spring Boot JPA - Native Query
- Spring Boot JPA - Custom Query
- Spring Boot JPA - Named Query
- Spring Boot JPA - Custom Methods
- Spring Boot JPA - Methods
- Spring Boot JPA - Unit Test Repository
- Spring Boot JPA - Application Setup
- Spring Boot JPA vs Hibernate
- Spring Boot JPA - Architecture
- Spring Boot JPA - Environment Setup
- Spring Boot JPA - Overview
- Spring Boot JPA - Home
Spring Boot JPA Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Spring Boot JPA - Repository methods
Let s now analyze the methods available in repository interface which we ve created.
Repository - EmployeeRepository.java
Following is the default code of Repository to implement CRUD operations on above entity, Employee.
package com.tutorialspoint.repository; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import com.tutorialspoint.entity.Employee; @Repository pubpc interface EmployeeRepository extends CrudRepository<Employee, Integer> { }
Now this repository contains following methods by default.
Sr.No | Method & Description |
---|---|
1 | count(): long returns the number of entities available. |
2 | delete(Employee entity): void deletes an entity. |
3 | deleteAll():void deletes all the entities. |
4 | deleteAll(Iterable< extends Employee > entities):void deletes the entities passed as argument. |
5 | deleteAll(Iterable< extends Integer > ids):void deletes the entities identified using their ids passed as argument. |
6 | existsById(Integer id):boolean checks if an entity exists using its id. |
7 | findAll():Iterable< Employee > returns all the entities. |
8 | findAllByIds(Iterable< Integer > ids):Iterable< Employee > returns all the entities identified using ids passed as argument. |
9 | findById(Integer id):Optional< Employee > returns an entity identified using id. |
10 | save(Employee entity): Employee saves an entity and return the updated one. |
11 | saveAll(Iterable< Employee> entities): Iterable< Employee> saves all entities passed and return the updated entities. |