liveBook · Manning

Aggregate

As explained in Spring in Action, Sixth Edition

An aggregate is a domain-driven design cluster of related objects treated as a unit for consistency and lifecycle management.

An aggregate groups related domain objects that must be handled together. One object acts as the aggregate root: other objects belong to its context and are managed through it. section 3.1.3

A Taco Cloud order illustrates the boundaries:

  • TacoOrder is the aggregate root and holds the order context. section 3.1.3
  • Taco belongs to a TacoOrder and cannot exist outside that context. section 3.1.3
  • Ingredient objects form separate aggregates and are referenced through IngredientRef rather than included in the order aggregate. section 3.1.3

The aggregate boundary shapes persistence. The application exposes one OrderRepository for TacoOrder, then saves its Taco objects and their IngredientRef rows as part of the same operation. The repository uses generated keys for the order and tacos, while a transaction coordinates the save. section 3.1.4

Saving an order aggregate

Saving a TacoOrder inserts the order first, obtains its database-generated ID, saves each Taco with that order ID, obtains each taco ID, and inserts IngredientRef rows linking ingredients to tacos. section 3.1.4

Figure 3.1 The tables for the Taco Cloud schema

Use the schema diagram to inspect the aggregate boundary and the separate Ingredient relationship. section 3.1.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Defines membership and demonstrates multi-table saving, but defers broader domain-driven design beyond aggregates and roots.
Examples
Uses TacoOrder, Taco, Ingredient, IngredientRef, SQL tables, and a JdbcOrderRepository save operation.
What it assumes
Assumes domain objects and database tables, while introducing domain-driven design aggregates and aggregate roots.
What you can do after
Build it from scratch by defining an aggregate root, repository, schema relationships, and coordinated JDBC persistence.
How it connects
Connects domain-driven design, aggregate roots, repositories, transactions, and relational database tables.

Also explained in

Compare how 3 books explain aggregate →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.