r/SpringBoot • u/iamwisespirit • Jan 09 '26
Question @Transactional method
What happen when I run executorsrrvice inside @Transactional method what would you offer like this scenario
2
Upvotes
r/SpringBoot • u/iamwisespirit • Jan 09 '26
What happen when I run executorsrrvice inside @Transactional method what would you offer like this scenario
View all comments
Show parent comment
1
u/Cautious-Necessary61 Jan 11 '26 edited Jan 11 '26
u/Service
public class OrderService {
private final OrderRepository orderRepository;
private final ExecutorService executorService;
public OrderService(OrderRepository orderRepository,
ExecutorService executorService) {
this.orderRepository = orderRepository;
this.executorService = executorService;
}
u/Transactional
public void createOrderAsyncWrong() {
Order order = new Order();
order.setStatus("CREATED");
orderRepository.save(order);
executorService.submit(() -> {
// NOT transactional
order.setStatus("PROCESSED");
orderRepository.save(order);
});
}
}