liveBook · Manning

Reconstitution

As explained in Clean Applications with Hexagonal Architecture

The reconstruction of a previously persisted domain object from its stored state.

Loading an existing aggregate is not the same as creating one. Reconstitution restores persisted state, including its status, without rerunning creation-time validation, raising events, or failing. This avoids rejudging past decisions against changed rules; handle legacy conflicts through migration, grandfathering, or revalidation on a later modification. section 9.2.3

Listing 9.5 Article: The aggregate root, with its two entry points
@Accessors(fluent = true)
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@AllArgsConstructor(access = AccessLevel.PRIVATE) #A
public class Article {
 
  @Getter
  @EqualsAndHashCode.Include
  private final ArticleId id; #B
 
  @Getter
  private final Title title;
  @Getter
  private final Content content;
  @Getter
  private final AuthorId authorId;
  @Getter
  private ArticleStatus status; #C
 
  // No getter to avoid direct manipulation of the collection.
  private final List<DomainEvent> domainEvents; #D
 
  public static Either<Error, Article>
    validateThenCreate(final ArticleId id, final Title title,
      final Content content, final AuthorId authorId) {
    final List<ValidationError> errors =
      new ArrayList<>(); #E
    Validations.mandatory(id, "id")
      .peekLeft(errors::add);
    Validations.mandatory(title, "title")
      .peekLeft(errors::add);
    Validations.mandatory(content, "content")
      .peekLeft(errors::add);
    Validations.mandatory(authorId, "authorId")
      .peekLeft(errors::add);
 
    return errors.isEmpty()
      ? Either.right(
          new Article(id, title, content, authorId,
          ArticleStatus.DRAFT, new ArrayList<>())) #F
      : Either.left(new Error.ValidationErrors(List.copyOf(errors)));
  }
 
  public static Article reconstitute(final ArticleId id,
    final Title title, final Content content, 
    final AuthorId authorId,
    final ArticleStatus status) { #G
    return new Article(id, title, content, authorId, status,
      new ArrayList<>());
  }
 
  // publish(...) and popDomainEvents() follow in listing 9.6
 
}

The Article aggregate has separate entry points for validated creation and reconstitution. section 9.2.3

How Clean Applications with Hexagonal Architecture covers it

How deep it goes
Defines faithful loading of persisted state without validation, events, or failure, and leaves changed-rule reconciliation to domain strategy.
Examples
Uses the Article aggregate and persisted ArticleStatus to contrast validateThenCreate with reconstitution.
What you can do after
Understand when to bypass creation validation while loading persisted aggregates and where to handle legacy-rule conflicts.
How it connects
Connects aggregate reconstitution to creation factories, domain invariants, data migration, grandfathering, and revalidation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clean Applications with Hexagonal Architecture. The section links point to the parts of the book it draws on.