Junior — Middle
How is process management carried out using Spring Data JPA?
sobes.tech AI
Answer from AI
In Spring Data JPA, transaction management is performed using the @Transactional annotation. It allows defining transaction boundaries at the method or class level. When a method annotated with @Transactional is called, Spring opens a transaction, and after the method execution, it either commits or rolls back the changes depending on the outcome.
Example of usage:
@Service
public class UserService {
@Autowired
private UserRepository userRepository;
@Transactional
public void createUser(User user) {
userRepository.save(user);
// additional operations that should be atomic
}
}
Thus, Spring Data JPA integrates with Spring's transaction mechanism, providing management of database operations without the need for manual transaction management.