Whenever implementing data modifying logic using Query annotation (insert, update or delete) in JpaRepository, both @Transactional (not necessarily on the repository method) and @Modifying have to be used.
java - Why do I have to use @Modifying with @Transactional in spring ...
Second question first: the Modifying annotation lets you execute DML (inserts, updates, deletes) and DDL using JPA Query annotations where you put the DML or DDL where the query would normally go. To answer the first question, i would expect to use this in a service layer annotated with @Transactional instead of putting the annotation on the Repository, because these operations seem likely to ...
Yes you need @Transactional when modifying data even with @Modifying that is only an annotation to let Spring Data know you have a @Query that changes stuff. The @Transactional marks the start AND end of a transaction. If you put it in your service layer everything called from within a single method participates in the same transaction.
java - Do we need both @Transactional and @Modifying annotation in ...