Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 31
JPQL
JPQL (Java Persistence Query Language) looks like SQL but operates on entities and fields, not tables and columns.
Course progress0%
Focus
3 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
JPQL (Java Persistence Query Language) looks like SQL but operates on entities and fields, not tables and columns. It's portable across DBs and integrates cleanly with Spring Data @Query.
Informative example
ts
public interface OrderRepository extends JpaRepository<Order, Long> {@Query("""select o from Order ojoin fetch o.items i -- avoid N+1where o.userId = :userIdand o.status in :statusesorder by o.createdAt desc""")List<Order> findFor(@Param("userId") Long userId,@Param("statuses") Collection<OrderStatus> statuses);@Modifying@Query("update Order o set o.status = :status where o.id = :id")int updateStatus(@Param("id") Long id, @Param("status") OrderStatus status);}
Best practices
- Use
join fetchto eliminate N+1 on collections you read together. @Modifying+@Transactionalfor bulk updates/deletes.- JPQL > native SQL when portability matters; native SQL > JPQL when DB-specific features matter.
Ready to mark this lesson complete?Track your journey across the entire course.