Query Methods by Method Name — Concept Check
Questions on Query Methods by Method Name. Spring Data parses method names like findByEmailAndStatus, countByCategory, or deleteByExpiredBefore and generates the corresponding JPQL automatically.
Questions in this quiz
8 questions on Query Methods by Method Name — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer wants to find users whose email starts with 'admin'. Which method should they use in Spring Data JPA?
- AfindByEmailIs('admin%')
- BfindByEmailEquals('admin%')
- CfindByEmailLike('admin%')
- DfindByEmailStartingWith('admin')
2.A service needs to delete all orders created before a specific date. Which method name should be used?
- AremoveOrdersByCreatedAtBefore(LocalDateTime date)
- BdeleteByCreatedAtBefore(LocalDateTime date)
- CdeleteOrdersByDateBefore(LocalDateTime date)
- DremoveByCreatedAtBefore(LocalDateTime date)
3.A developer mistakenly uses 'findByAgeGreaterThanEqual' but wants to find users older than a certain age. What is the issue?
- AThe method will not compile due to syntax error.
- BThe method will throw an exception at runtime.
- CThe method will only find users younger than the specified age.
- DThe method will include users of the specified age.
4.Which method would efficiently check if any user exists with a given email?
- AfindByEmailIsNotNull(String email)
- BcountByEmail(String email) > 0
- CfindByEmail(String email) != null
- DexistsByEmail(String email)
5.A developer needs to count orders for a customer, excluding a specific status. Which method should they use?
- AcountByCustomerIdAndStatusNot(Long customerId, String status)
- BcountByCustomerIdAndStatusIsNot(Long customerId, String status)
- CcountOrdersByCustomerIdIgnoringStatus(Long customerId, String status)
- DcountByCustomerIdAndStatusExcluding(Long customerId, String status)
6.A developer wants to find the top 5 most expensive products. Which method name is correct?
- AfindTopFiveByOrderByPriceDesc()
- BfindFirst5ByOrderByPriceDesc()
- CfindTop5ByOrderByPriceDesc()
- DfindTop5ProductsByPriceDesc()
7.A developer uses 'findByPhoneIsNull()' to find users without a phone number. What does this method return?
- AUsers with a phone number
- BUsers with no phone number
- CUsers with phone number as 'NULL' string
- DUsers with phone number as empty string
8.What is the purpose of the 'OrderBy' keyword in method name queries?
- ATo filter results by a specific order
- BTo sort the query results
- CTo limit the number of results returned
- DTo group results by a specific field