Derived Query Methods in Repositories

Let’s go over the derived query methods of the JPA repositories provided by the Spring Data JPA.

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, and delete, tells Spring Data JPA the action to be done.
  • After the By keyword, Spring Data JPA expects conditions like Equals, GreaterThan, and After on the properties of the entity class. Also, we can create complex queries by utilizing concatenators like And and Or 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.