JPQL with @Query
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
@Modifyingfor update/delete queries (they bypass the persistence context, so use sparingly).
Draft outline details
Demonstration
@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.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.