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.
Loading...
Related Quiz
- Imagine you are developing a Spring Boot application with a read-heavy database workload. How would you optimize the application and database connectivity to handle high read requests efficiently?
- How can you ensure that the ApplicationContext is not loaded while performing unit testing on web layers in Spring Boot?
- You are assigned to implement a high-throughput, low-latency service using Spring Boot. How would you leverage WebFlux and Reactive Streams to achieve these requirements?
- What is the significance of the @Transactional annotation in Spring Data JPA?
- How can you define a property in the YAML configuration file in Spring Boot?