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.
3 points to say:
- JPQL talks about entities and fields, not tables and columns.
- A bulk update ignores entities already in memory.
- 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.