In what scenario would you use the @Modifying annotation in a Spring Data JPA repository method?

  • When creating a new entity instance in the repository.
  • When performing a read operation on an entity.
  • When executing a non-selecting (e.g., UPDATE or DELETE) query.
  • When retrieving a collection of entities.
The @Modifying annotation is used in a Spring Data JPA repository method when you want to execute a non-selecting query, such as an UPDATE or DELETE operation, on the database. This annotation informs Spring that the method will modify the database, allowing it to manage the transaction appropriately. The other options are not suitable scenarios for using @Modifying.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *