Transaction Management In Spring Data JPA - @Transactional

    Question 1DATA JPA - Basics of @Transactional

    What is the primary purpose of the @Transactional annotation in Spring Data JPA?

    Question 2DATA JPA - Default Rollback Behavior

    By default, @Transactional in Spring rolls back on which type of exceptions?

    Question 3DATA JPA - Code Snippet (Rollback Example)

    What will happen to the database changes in the following method?

    @Transactional public void saveData() { userRepo.save(new User("John")); if (true) { throw new RuntimeException("Failure!"); } }

    Question 4DATA JPA - Checked Exception Handling

    What will happen in this case?

    @Transactional public void saveData() throws IOException { userRepo.save(new User("Alice")); throw new IOException("Checked Exception!"); }

    Question 5DATA JPA - Propagation Behavior

    Which propagation type ensures that if a transaction already exists, the method joins it; otherwise, a new one is created?

    Question 6DATA JPA - Code Snippet (REQUIRES_NEW)

    What happens in this case?

    @Transactional public void processOrder() { saveOrder(); // REQUIRED saveAudit(); // REQUIRES_NEW }

    Question 7DATA JPA - Isolation Levels

    Which isolation level prevents dirty reads but allows non-repeatable reads?

    Question 8DATA JPA - Code Snippet (Transactional ReadOnly)

    What effect does @Transactional(readOnly = true) have?

    @Transactional(readOnly = true) public List<User> getAllUsers() { return userRepo.findAll(); }

    Question 9DATA JPA - Transaction Propagation Edge Case

    What happens if a method annotated with @Transactional(propagation = Propagation.MANDATORY) is called without an existing transaction?

    Question 10DATA JPA - Best Practice for @Transactional Placement

    Where is the best place to apply @Transactional in a Spring application?