Derived queries
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
write queries from method names, and know when to stop.
Planned topics
- Spring parses names like
findByNameContainingIgnoreCaseinto JPQL. - Keywords:
And,Or,Between,LessThan,OrderBy,Containing,IsNull. - Great for one or two conditions.
- When the name grows past about 3 conditions, it is hard to read: switch to
@Query. - Typos in property names fail at startup, which is a useful early warning.
Draft outline details
Demonstration
List<Product> findByCategoryIdAndPriceAmountLessThanOrderByNameAsc(Long categoryId, BigDecimal max); // too long
Optional<Product> findBySku(String sku); // goodCheck your understanding
When should you replace a derived query with @Query?
Show answer
When the name becomes hard to read, around three or more conditions.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.