Custom Spring Data Repositories
Learn how to create custom Spring Data repositories to add extra features of persistence.
We'll cover the following...
We'll cover the following...
At times, the default methods available through Spring Data repositories aren’t enough for our specific needs. In this case, we can choose to create custom Spring Data repositories with abstract methods.
The CustomCustomerRepository interface
First, let’s create a custom repository interface CustomCustomerRepository for the Customer entity with the findCustomerCustom abstract method.
package com.smartdiscover.repository;import com.smartdiscover.entity.Customer;import org.springframework.stereotype.Repository;@Repositorypublic interface CustomCustomerRepository {Customer findCustomerCustom(String firstName, String lastName);}
Explanation:
- Lines 6–7: We