Spring Boot Tutorial
Spring Boot - Software Setup and Configuration (STS/Eclipse/IntelliJ)
Prerequisite (Spring Core Concepts)
Spring Boot Core
Spring Boot with REST API
Spring Boot with Database and Data JPA
Spring Boot with Kafka
Spring Boot with AOP
Both CrudRepository
and JpaRepository
are part of the Spring Data JPA project, and they provide a way to perform database operations on entities without the need for boilerplate code. However, there are notable differences between them:
Hierarchy:
CrudRepository
and PagingAndSortingRepository
. Thus, JpaRepository
contains API for CRUD operations, paging and sorting operations, and some JPA-specific operations.Feature Set:
CrudRepository
and PagingAndSortingRepository
. It adds JPA-related functionality, such as flushing the persistence context and deleting records in batches.Intended Datastore:
CrudRepository
is more general and can be used with other Spring Data projects, like Spring Data JDBC, Spring Data MongoDB, etc.Return Type of Save Method:
save(…)
method returns the saved entity.CrudRepository
.Batch Operations:
flush()
and saveAndFlush(…)
methods for batch operations, and methods like deleteInBatch(…)
for batch deletes.Pagination:
PagingAndSortingRepository
, allowing for easy pagination and sorting using Pageable
and Sort
parameters.When you're working with Spring Boot and JPA, and you need to create a repository, you often have to decide between these interfaces. The decision typically hinges on the specific requirements of your application:
CrudRepository
might suffice.JpaRepository
would be more appropriate.Most Spring Boot applications that use JPA tend to lean towards JpaRepository
due to the comprehensive set of features it offers out of the box.
Custom queries and methods with CrudRepository
and JpaRepository
in Spring Boot:
JpaRepository
):public interface UserRepository extends JpaRepository<User, Long> { List<User> findByLastName(String lastName); }