Skip to content
Ameen Abozaid
Planned lessonJNR-031-L02

Transaction boundaries

  • Lesson 2 of 8
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

put the transaction around one business operation.

Planned topics

  • The boundary is the business operation, for example "place order", not a single SQL statement.
  • Put @Transactional on service methods, not on controllers or repositories.
  • Repository calls inside join the service's transaction.
  • Without a boundary each repository call commits alone, and a failure leaves partial data.
  • Keep the business operation as one public service method.
Draft outline details

Demonstration

java
@Service
public class OrderService {
    @Transactional
    public Order placeOrder(PlaceOrderCommand cmd) {
        stockService.reserve(cmd.lines());   // same transaction
        return orderRepository.save(Order.from(cmd));
    }
}

Check your understanding

Which layer owns the transaction?

Show answer

The service layer.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.