0
0
Spring Bootframework~20 mins

Custom query methods by naming convention in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spring Data Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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)?
AAll users with age less than 30
BAll users with age exactly 30
CAll users with age greater than 30
DAll users with age greater than or equal to 30
Attempts:
2 left
💡 Hint
Think about the meaning of 'GreaterThan' in the method name.
📝 Syntax
intermediate
2: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?
AList<User> findByLastName_And_Active(String lastName, boolean active);
BList<User> findByLastNameAndActive(String lastName, boolean active);
CList<User> findByLastNameActive(String lastName, boolean active);
DList<User> findByLastNameOrActive(String lastName, boolean active);
Attempts:
2 left
💡 Hint
Use 'And' to combine conditions in method names.
🔧 Debug
advanced
2:00remaining
Why does this method cause a runtime error?
Consider this method in a Spring Data JPA repository:
List findByEmailContainingIgnoreCaseOrderByAgeDesc(String emailPart);
At runtime, calling this method causes an error. What is the most likely cause?
AThe method name is valid but the entity does not have an 'age' field
BThe method name is too long and exceeds Spring Data limits
CThe method name uses unsupported keywords 'ContainingIgnoreCase' and 'OrderBy' together
DThe method should return a single User, not a list
Attempts:
2 left
💡 Hint
Check if all fields in the method name exist in the entity.
🧠 Conceptual
advanced
2: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: List findDistinctByCity(String city);
AIt removes duplicate users from the result list
BIt filters users with distinct cities
CIt sorts the users by city
DIt returns only one user from the city
Attempts:
2 left
💡 Hint
Think about what 'distinct' means in database queries.
state_output
expert
2:00remaining
What is the size of the result list after calling this method?
Given a User entity with fields 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)?
A2
B5
C4
D3
Attempts:
2 left
💡 Hint
The 'Between' keyword includes both start and end values.