Skip to content
Ameen Abozaid
Planned lessonJNR-029-L02

Derived queries

  • Lesson 2 of 7
  • Junior
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 findByNameContainingIgnoreCase into 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

java
List<Product> findByCategoryIdAndPriceAmountLessThanOrderByNameAsc(Long categoryId, BigDecimal max); // too long
Optional<Product> findBySku(String sku);                                                             // good

Check 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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.