Skip to content
Ameen Abozaid
Planned lessonJNR-029-L03

JPQL with @Query

  • Lesson 3 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 explicit queries on entities.

Planned topics

  • JPQL queries entities and their fields, not tables and columns.
  • Use named parameters with @Param.
  • Optional filters can be written as (:name is null or lower(p.name) like lower(concat('%', :name, '%'))).
  • Never concatenate input; parameters are safe.
  • Add @Modifying for update/delete queries (they bypass the persistence context, so use sparingly).
Draft outline details

Demonstration

java
@Query("""
    select p from Product p
    where p.category.id = :categoryId and p.price.amount <= :max
    order by p.name
    """)
List<Product> findAffordable(@Param("categoryId") Long categoryId, @Param("max") BigDecimal max);

Check your understanding

Does JPQL use table names or entity names?

Show answer

Entity names.

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.