Challenge - 5 Problems
Spring Data Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Spring Data JPA method return?
Given the method
List findByAgeGreaterThan(int age); in a repository interface, what will it return when called with findByAgeGreaterThan(30)?Attempts:
2 left
💡 Hint
Think about the meaning of 'GreaterThan' in the method name.
✗ Incorrect
The method name 'findByAgeGreaterThan' tells Spring Data JPA to find all users whose age is strictly greater than the given value.
📝 Syntax
intermediate2:00remaining
Which method signature is valid for finding users by last name and active status?
You want to create a method in a Spring Data JPA repository to find users by their last name and whether they are active. Which method signature is valid?
Attempts:
2 left
💡 Hint
Use 'And' to combine conditions in method names.
✗ Incorrect
Spring Data JPA supports 'And' and 'Or' keywords to combine conditions. The method name must follow camel case with these keywords.
🔧 Debug
advanced2:00remaining
Why does this method cause a runtime error?
Consider this method in a Spring Data JPA repository:
At runtime, calling this method causes an error. What is the most likely cause?
List findByEmailContainingIgnoreCaseOrderByAgeDesc(String emailPart); At runtime, calling this method causes an error. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check if all fields in the method name exist in the entity.
✗ Incorrect
If the entity lacks the 'age' field, Spring Data cannot create the query and throws an error at runtime.
🧠 Conceptual
advanced2:00remaining
What is the effect of using 'Distinct' in method names?
In Spring Data JPA, what does adding 'Distinct' to a query method name do?
For example:
For example:
List findDistinctByCity(String city); Attempts:
2 left
💡 Hint
Think about what 'distinct' means in database queries.
✗ Incorrect
'Distinct' ensures the query returns unique results without duplicates.
❓ state_output
expert2:00remaining
What is the size of the result list after calling this method?
Given a User entity with fields
Assume the database has users with ages: 20, 25, 30, 35, 40.
What is the size of the list returned by
id, name, age and a repository method:List findByAgeBetween(int start, int end); Assume the database has users with ages: 20, 25, 30, 35, 40.
What is the size of the list returned by
findByAgeBetween(25, 35)?Attempts:
2 left
💡 Hint
The 'Between' keyword includes both start and end values.
✗ Incorrect
Ages 25, 30, and 35 are included, so the list size is 3.