Learn how to create new Spring Data JPA CrudRepository interfaces using JPA entities.
- [Instructor] The classic means to create, read, update, and delete JPA entities was to invoke the entity manager. While better than straight JTBC or spring JTBC template, it's use still resulted in repetitive boiler plate code. Functions were the same only the data was different. With Spring Data JPA, we write less code to accomplish the same functionality. To use Spring Data JPA for a JPA entity we declare a Java interface class that extends from CrudRepository, where T is the domain type the repository manages and ID is the type of the ID of the entity the repository manages.
So let's create the tour JPA repository interface. First I'm going to create a package First I'm going to create a package called repo under com example EC. Then a tour repository interface. And I'm going to extend from crud repository. The first parameter is tour. The second parameter is the type of the ID of tour, The second parameter is the type of the ID of tour, which in this case is integer.
So what does that give us? Well a lot actually. By extending from crud repository, spring data JPA provides the interface for all these crud methods and implements them at run time. The create and update methods, the read methods, and the delete methods. Now let's do the same for tour package. Tour package repository, which is an interface.
Extends crud repository. Our tour package. And it's ID type is string. And it's ID type is string. So for tour package repository, there are the create update methods, the read methods, and the delete methods.
- Setting up the project
- Building, deploying, and launch the microservice
- Declaring Spring Data JPA repository interfaces
- Invoking repositories
- Using Spring Data query methods
- Exposing RESTful APIs with Spring Data REST
- Using the /search resource to invoke query methods
- Paging and sorting
- Declaring a new REST controller
- Creating HTTP methods for creating, reading, updating and deleting persistent data.