Creating a Spring Data repository
What is the best query? The one we don’t have to write!
This may sound absurd, but Spring Data really makes it possible to write lots of queries…without writing them. The simplest one is based on the repository pattern.
This pattern was originally published in Patterns of Enterprise Application Architecture, Martin Fowler, Addison-Wesley.
A repository essentially gathers all the data operations for a given domain type in one place. The application talks to the repository in domain speak, and the repository in turn talks to the data store in query speak.
Before Spring Data, we had to write this translation of action by hand. But Spring Data provides the means to read the metadata of the data store and perform query derivation.
Let’s check it out. Create a new interface called VideoRepository.java
, and add the following code:
public interface VideoRepository extends JpaRepository <VideoEntity, Long...