Example with Spring Data JPA
Let's have a look at a code example that implements AccountPersistenceAdapter from the preceding figures. This adapter will have to save and load accounts to and from the database. We saw the Account entity in Chapter 4, Implementing a Use Case, but here is its skeleton again for reference:
package buckpal.domain;
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Account {
  @Getter private final AccountId id;
  @Getter private final ActivityWindow activityWindow;
  private final Money baselineBalance;
  public static Account withoutId(
          Money baselineBalance,
          ActivityWindow activityWindow) {
    return new Account(null, baselineBalance, activityWindow);
  }
  public static Account withId(
          AccountId...