From the course: Spring Data
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Spring Data Specifications - Spring Tutorial
From the course: Spring Data
Spring Data Specifications
- [Instructor] Thus far, we have only learned about Spring Data queries whose parameters are known at implementation. In some applications, we may not know this until runtime. We need to be able to query the data store in a dynamic fashion. In this chapter, we are going to look at various ways to create dynamic queries with Spring Data. Spring Data commons query methods are static. Filtering by multiple fields requires several query methods covering all possible combinations. In this course repository example, filtering just by instructor, credits, and department require seven different query methods plus logic to decide which method to invoke. The original course DAO provides dynamic filters of the course table via Java Persistence Criteria API. This API requires first instantiating a criteria builder from the entity manager to create a criteria query. The root of the course specifies the root table. Multiple predicates are built on the fly at runtime and applied to the criteria…