Return to site

🍃🎓 SPRING CERTIFICATION QUESTION: Spring repository prefixes

· spring,vcp,java

Which prefixes are allowed in the query builder mechanism built into Spring Data repository.

find…By (ex: findDistinctPeopleByLastnameOrFirstname)

read…By (ex: readDistinctPeopleByLastnameOrFirstname)

show…By (ex: showDistinctPeopleByLastnameOrFirstname)

get…By (ex: getDistinctPeopleByLastnameOrFirstname)

search…By (ex: searchDistinctPeopleByLastnameOrFirstname)

stream…By (ex: streamDistinctPeopleByLastnameOrFirstname)

#spring #certificationquestion #vcp

According to the Spring Data JPA documentation¹, the following prefixes are allowed in the query builder mechanism built into Spring Data repository:

- find…By

- read…By

- query…By

- search…By

- stream…By

These prefixes are general query methods that return typically the repository type, a collection or streamable subtype or a result wrapper such as Page, GeoResults or any other store-specific result wrapper. They can be used as findBy…, findMyDomainTypeBy… or in combination with additional keywords¹.

The prefix show…By is not a valid prefix for the query builder mechanism. The prefix get…By is valid, but it is not listed in the documentation as a general query method. It is used as a synonym for find…By².

Source: Conversation with Bing, 12/5/2023

(1) Repository query keywords :: Spring Data JPA.

(2) Derived Query Methods in Spring Data JPA Repositories.

(5) Combining Spring Data query builder with Spring Data JPA Specifications .... https://stackoverflow.com/questions/28442655/combining-spring-data-query-builder-with-spring-data-jpa-specifications