- Spring Data JPA
- REST Repository
- MySQL Driver
- Lombok
- Create database for Entities [create-database.sql] [countries-and-states.sql]
- Configure JDBC connection and Hibernate dialect in application.properties
- Create JPA Entity classes [Product] [ProductCategory] [Country] [State]
- Create Repositories
[ProductRepository] [ProductCategoryRepository] [CountryRepository] [StateRepository]
- Use @RepositoryRestResource to customize JSON entry and API endpoint
- Create custom query methods by Query Methods
- Customize base path for REST API in application.properties
- Create Spring Data REST Configuration with @Configuration implements RepositoryRestConfigurer for custom configuration
[DataRestConfig]
- Disable certain HTTP methods for certain Entities
- Expose Entity id fields for the API
- Inject JPA entity manager (recommend by the constructor): to retrieve list of all Entity types
- Alternative method: declare field by uppercase
Id
instead ofid
. However, this is not a documented feature -> not recommend
- [Hibernate] @CreationTimestamp & @UpdateTimestamp [Product]
- [SpringDataJPA&Lombok]Using @Data on both Entity classes in the OneToMany relationship may cause bug -> Use @Data for one side, @Getter and @Setter for the other.
- [SpringDataJPA] Add @CrossOrigin to Repositories to accept calls from web browser script for the origin (Angular app)
- [SpringDataJPA] Use @Query to define a custom query method in the JPA Repository
- [SpringDataJPA] JPA Repository method starts with
findBy...
will be exposed by Data REST as endpoint/search/findBy...
[ProductRepository] - [SpringDataREST] Spring Data REST API supports pagination
- Returns 20 entries per page by default
- Endpoint:
<entities>?page=<number>&size=<number
s- When working with Spring Data REST we should actually use @Param instead of @RequestParam.