Recall & Review
beginner
What is a custom query method by naming convention in Spring Boot?
It is a method in a Spring Data repository interface whose name follows a pattern that Spring Data understands to create a database query automatically without writing SQL.
Click to reveal answer
intermediate
How does Spring Boot know what query to run from a method name?
Spring Data parses the method name to identify keywords like findBy, countBy, and conditions like And, Or, GreaterThan, then builds the query based on the entity's fields.
Click to reveal answer
beginner
Example: What does the method name
findByLastNameAndAgeGreaterThan mean?It means find all records where the lastName field matches the given value AND the age field is greater than the given number.
Click to reveal answer
intermediate
Can you use custom query methods for sorting and limiting results?
Yes, by adding keywords like OrderBy and using Pageable parameters, you can sort and limit results using naming conventions.
Click to reveal answer
beginner
What happens if a method name does not follow Spring Boot's naming conventions?
Spring Data will throw an error or fail to create the query because it cannot understand how to translate the method name into a database query.
Click to reveal answer
Which prefix is used to create a method that returns a list of entities matching a condition?
✗ Incorrect
The prefix 'findBy' tells Spring Data to find and return entities matching the condition.
What does the method name
countByStatus do?✗ Incorrect
'countBy' counts how many entities match the condition.
Which keyword would you use to combine two conditions in a method name?
✗ Incorrect
'And' combines two conditions that both must be true.
How do you specify sorting in a custom query method name?
✗ Incorrect
'OrderBy' is used to specify sorting in the method name.
What will happen if you name a method
findAllUsers in a Spring Data repository?✗ Incorrect
The method name does not follow the naming convention for queries, so Spring Data cannot create a query.
Explain how Spring Boot creates database queries from custom method names in repositories.
Think about how the method name tells Spring Boot what to look for in the database.
You got /5 concepts.
Describe how you would write a method name to find all records where age is greater than 30 and status is 'active'.
Combine conditions with 'And' and use comparison keywords.
You got /5 concepts.