Chapter 4. Adding Custom Functionality to JPA Repositories
We have learned how we can manage our entities and create database queries with Spring Data JPA. We have also learned how we can sort and paginate query results. However, if we take a purist architectural point of view, we notice that the described solutions are not following the separation of concerns principle. In fact, our service layer contains code that reveals the inner workings of our repository layer.
This is a trade off between architectural purity and productivity. As always, this choice has some consequences. If we have to migrate our application away from Spring Data JPA, we have to make changes to both the service and repository layer. However, how many times have we heard that the repository layer of an application has to be changed so radically? Exactly. These situations are very rare. Thus, this risk is worth taking when the reward is high.
The techniques described in this chapter can be used to hide the implementation...