private void transfer(final Date date, final Account account1, final Account account2) {
    persistence.runInTransaction(
        em -> {
          BigDecimal amount1 = randomExpenseAmount(account1, date, 0.5);
          if (BigDecimal.ZERO.compareTo(amount1) >= 0) return;

          BigDecimal amount2 = transferAmount(account1, account2, amount1);

          Operation operation = metadata.create(Operation.class);
          operation.setOpType(OperationType.TRANSFER);
          operation.setOpDate(date);
          operation.setAcc1(account1);
          operation.setAmount1(amount1);
          operation.setAcc2(account2);
          operation.setAmount2(amount2);
          em.persist(operation);

          log.info(
              "Transfer: "
                  + date
                  + ", "
                  + account1.getName()
                  + ", "
                  + amount1
                  + ", "
                  + account2.getName()
                  + ", "
                  + amount2);
        });
  }
  private void expense(final Date date, final Account account, final Context context) {
    persistence.runInTransaction(
        em -> {
          int categoryIdx =
              (int) Math.round(Math.random() * (context.expenseCategories.size() - 1));
          Category category = context.expenseCategories.get(categoryIdx);
          if (category == null) return;

          int categoryWeight = context.expenseCategories.size() - categoryIdx;
          BigDecimal amount = randomExpenseAmount(account, date, 0.1 + (categoryWeight * 0.05));
          if (BigDecimal.ZERO.compareTo(amount) >= 0) return;

          Operation operation = metadata.create(Operation.class);
          operation.setOpType(OperationType.EXPENSE);
          operation.setOpDate(date);
          operation.setAcc1(account);
          operation.setCategory(category);
          operation.setAmount1(amount);
          em.persist(operation);

          log.info("Expense: " + date + ", " + account.getName() + ", " + amount);
        });
  }