SteelReed

Search

Search posts, questions…

JPA & HibernateQuestion 15 / 24

Middle

When do you use derived queries, @Query/JPQL and @Modifying in Spring Data JPA?

Short answer

A derived query builds the query from the method name (findByEmailAndStatus) and fits simple conditions. Joins or complex conditions use @Query with JPQL. @Modifying is required for UPDATE/DELETE and skips the persistence context.

simple conditionjoin, OR, aggregatebulk UPDATE, DELETEWhat kind of query?derived query@Query JPQL@Query + @Modifying

3 points to say:

  1. JPQL talks about entities and fields, not tables and columns.
  2. A bulk update ignores entities already in memory.
  3. Always bind parameters; never concatenate strings.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.