Derived Query Methods in Repositories
Let’s go over the derived query methods of the JPA repositories provided by the Spring Data JPA.
We'll cover the following
Derived query methods are dynamic methods provided by Spring Data to operate based on the criteria. The naming convention used for a derived method helps Spring Data JPA identify the action and the conditions for the query. Therefore, the name contains two parts— an introducer and a criteria separated by the first By
keyword.
- The introducer, such as
find
,count
, anddelete
, tells Spring Data JPA the action to be done. - After the
By
keyword, Spring Data JPA expects conditions likeEquals
,GreaterThan
, andAfter
on the properties of the entity class. Also, we can create complex queries by utilizing concatenators likeAnd
andOr
keywords with a combination of properties.
For instance, let’s look at a few derived query methods.
Get hands-on with 1400+ tech skills courses.