[MUSIC] Once you've created a series of classes that are annotated with the @entity annotation and given them IDs, or unique IDs of some sort, to reference them in the database, what you need is a way to actually interact with the database through JPA and be able to store and find and retrieve the data or the objects that your persisting into the database. The way that we do that in JPA or with Spring is by creating a repository. So in Spring we can create an interface to a repository. So let's create a video repository. So we'll have a public interface. [BLANK_AUDIO] And we'll call this VideoRepo. And we want it to extend, and this is a really important part, is we're going to extend the other interface called CrudRepository, and we have to parametrize the CrudRepository with the types that we are doing. So in this case it's going to be Video, Long. And I've just gone down on one line here where I'm parametrizing CrudRepository. So this is our class, or actually our interface, and the reason that we do this is all we're going to specify the interface to saving updating, retrieving, our different video objects. And the Spring framework is actually going to fill in the details or the implementation of this interface. This is one of the beautiful parts of this approach, is we have all of this complex work that needs to happen to save these classes annotated with entity, these instances, into the database. And all we're going to do is define the interface that we would like to have in order to save them and Spring is automatically going to fill in the object that will be implementing this interfacing and saving and retrieving the objects for us. The interface just gives us a way of interacting with that object through some nice mechanism. Now what CrudRepository is, is it's an interface for a standard repository that can save objets in the database. And what CRUD stands for create, read, update, and delete. So it's giving us the ability to create new entities in the database. So we can create a new video object and store it in the database. Read, because we can read existing stored video objects. Update, because we can take an existing object, we can change some of its properties, and update its representation in the database. And then finally, delete in CRUD, because we can delete video objects. So by default, we automatically get a series of methods that are inherited from this CrudRepository. We get save. We can find objects we've stored by filling in the unique ID that we assigned to that object. And if you go and look at how we're paramaterizing this CrudRepository interface that we're extending, the second parameter, the type we're providing is our ID type. So, this is the type of our ID or our unique ID that we're that we've included in our class as the ant entity annotation. And this is the type that our repository is operating on. So these are the type of objects that we're going to be storing through the repository and retrieving through the repository. So by, by extending CrudRepository we get all the basic operations to save objects or types of videos into the database. We get the ability to retrieve by finding one or all, or running a query to find a series of, of different video objects that meet our parameters in the database. So, immediately we get a lot of work done for us by Spring. One of the most important functions that we typically need above save or delete of the video objects that we're going to be storing is the ability to find video objects that meet some criteria. So for example we might want to go and search for all the videos that have a particular name. Or all of the videos that have a particular category, if we had added a category member variable to our video. And so, to inde-, be able to do that, we can't do that with the default methods that are provided by CRUD. We have to have something beyond simply search by the unique id of a video, or something beyond, give me all videos. We want to be able to search based on different member variable values of the objects that we've stored. So the way that we do that with the repository is by defining in our interface new methods that provide the type of searches that we want. So for example, we could go and add a new search like public list, because we're going to a series of them, video findByName. And then we could have a String for the name. And this simple method that we've just added to our interface is going to tell Spring that it needs to go and create a way of querying the data by the name member variables of all the objects that have been stored. So, what it will see is, I'm going to have to create a method of querying that's going to return more than one video object from the database. The find here and by is telling Spring that this is going to be a query that it needs to run. And the name is telling it the criteria of that query. Basically this is saying, find every video object where video.name equals the value that's passed in here, n. So, behind the scenes, Spring is automatically constructing an implementation of this interface method that can query all of your videos and return any stored object, if you had a member variable name equal to the value that's passed in. So we're actually running a query, defining a query across the member variables in our stored objects based on the naming of the method. Similarly, we can go and add additional fields that we'd like to query by. So, for example, we could say, public lists video, and we could say, find by name. And if we had, let's say, a category member variable. [BLANK_AUDIO] And then we can define our parameters to this thing to be string name, and string category. And Spring will automatically realize it needs to go and find all objects where video, and that's what this is telling us again, is this is defining our query. Video.name equals the name that was passed in. And we also have, at the same time, video.category if we had a category member variable equals the category value that we passed in. So, simply by going and adding and defining new methods on our interface that start with find, and then provide a series of query parameters. So in this case we're saying we're going to query across name and category, and then providing method parameters for each of those things. Spring can automatically go and figure out how to construct a query and find all of those objects. So you can very quickly add all kinds of complex search mechanisms simply by defining new methods and giving them the appropriate naming. And there are many more things that you can do with the method naming to do more advanced querying capabilities. And if you go and look at the spring data JPA documentation or a repository documentation, you'll see all of those different capabilities that are provided. But for our case, these are going to be sufficient for the things that we need to do to create our video upload service.