I have a business service method that calls a Repository and i want to know how i can rollback a transaction.Say for example
@Transactionl
public class OrderService {
@inject
OrderRepository orderRepository;
@inject
InventoryRepository inventoryRepository;
@inject
Order order;
@inject
Item item;
public Order createOrder (Order order) {
orderRepository.save(order);
}
public Item reduceInventory(Item item) {
inventoryRepository.update(item);
}
What i want is when a checked exception like a SQL Exception occurs then I want both createOrder and reduceInventory should both be rolledback.Say after creating the order when i go reduceInventory if the item count is negative i dont ant the order to be created at all.
Thanks in advance