Adding custom functionality to all repositories
Sometimes we have to add custom functionality to all repositories. In this section, we will learn how we can do this and create a custom repository method that is used to delete an entity by using its ID.
We can add custom functionality to all repositories by following these steps:
Create a base interface that declares the custom methods.
Implement the created interface.
Create a repository factory bean.
Configure Spring Data JPA to use our repository factory bean.
Create a repository interface.
Implement a service class that uses the custom functionality.
Creating the base repository interface
We start by creating a base repository interface that declares the methods that are available in the actual repositories. We can do this by:
Creating an interface that takes the type of the managed entity and the type of its ID as a type parameter.
Extending both the
JpaRepository<T, ID>
andQueryDslPredicateExecutor<T>
interfaces in our base repository...