You are working on a Spring Boot project using Spring Data JPA, and you are tasked with implementing a feature that requires a custom query and also modifies the state of the underlying database. How would you implement this while ensuring that the changes are committed to the database?

  • Using a read-only transaction.
  • Using a read-write transaction with the @Transactional annotation on the method that modifies the data.
  • Using an in-memory database for testing purposes to avoid committing changes to the actual database during development.
  • Using two separate transactions for reading and writing, ensuring that the write transaction commits the changes.
In this scenario, you should use two separate transactions for reading and writing. The read transaction fetches the data, and the write transaction modifies the data and commits the changes to the database. This approach ensures that changes are committed while maintaining the integrity of the database. Using read-only transactions or in-memory databases for testing would not fulfill the requirement.
Add your answer
Loading...

Leave a comment

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