Spring Certified Professional 2023 · Free Practice Question Medium

Question 36

Which prefixes are allowed in the query builder mechanism built into Spring Data repository? (select 5)

  • A

    read…By (ex: readDistinctPeopleByLastnameOrFirstname)

  • B

    get…By (ex: getDistinctPeopleByLastnameOrFirstname)

  • C

    search…By (ex: searchDistinctPeopleByLastnameOrFirstname)

  • D

    find…By (ex: findDistinctPeopleByLastnameOrFirstname)

  • E

    stream…By (ex: streamDistinctPeopleByLastnameOrFirstname)

  • F

    show…By (ex: showDistinctPeopleByLastnameOrFirstname)

Reveal correct answers

Correct answers: A, B, C, D, E

Explanation

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 typically return 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. https://docs.spring.io/spring-data/jpa/reference/repositories/query-keywords-reference.html

(2) Derived Query Methods in Spring Data JPA Repositories. https://www.baeldung.com/spring-data-derived-queries

(3) How query method of Spring Data JPA generate query?. https://stackoverflow.com/questions/70449033/howhttps://www.baeldung.com/spring-data-derived-queries

(4) Spring Data JPA Tutorial Part Three: Custom Queries with Query Methods .... https://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-three-custom-queries-with-query-methods/

(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

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need