title: How is the state of the entity being persisted between calls to EventSourcingHandlers?
body: <p>In the <a href="https://github.com/AxonIQ/giftcard-demo" rel="nofollow noreferrer">Axon Giftcard demo</a>, there is a <code>GiftCard</code> class which is annotated as @Aggregate:</p>
  
  <pre><code>@Aggregate
  @Profile("command")
  public class GiftCard {
  
      private final static Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
  
      @AggregateIdentifier
      private String id;
      private int remainingValue;
  
      @CommandHandler
      public GiftCard(IssueCmd cmd) {
          log.debug("handling {}", cmd);
          if(cmd.getAmount() &lt;= 0) throw new IllegalArgumentException("amount &lt;= 0");
          apply(new IssuedEvt(cmd.getId(), cmd.getAmount(), cmd.getCurrency()));
      }
  
      @CommandHandler
      public void handle(RedeemCmd cmd) {
          log.debug("handling {}", cmd);
          if(cmd.getAmount() &lt;= 0) throw new IllegalArgumentException("amount &lt;= 0");
          if(cmd.getAmount() &gt; remainingValue) throw new IllegalStateException("amount &gt; remaining value");
          apply(new RedeemedEvt(id, cmd.getAmount()));
      }
  
  ...
      @EventSourcingHandler
      public void on(IssuedEvt evt) {
          log.debug("applying {}", evt);
          id = evt.getId();
          remainingValue = evt.getAmount();
          currency = evt.getCurrency();
          log.debug("new remaining value: {}", remainingValue);
          log.debug("new currency: {}", currency);
      }
  
     @EventSourcingHandler
      public void on(RedeemedEvt evt) {
          log.debug("applying {}", evt);
          remainingValue -= evt.getAmount();
          log.debug("new remaining value: {}", remainingValue);
      }
  ...
  </code></pre>
  
  <p>The command and event classes are defined in Kotlin code:</p>
  
  <pre><code>data class IssueCmd(@TargetAggregateIdentifier val id: String, val amount: Int)
  data class IssuedEvt(val id: String, val amount: Int)
  data class RedeemCmd(@TargetAggregateIdentifier val id: String, val amount: Int)
  data class RedeemedEvt(val id: String, val amount: Int)
  </code></pre>
  
  <p>Let's say the following two commands are put on the command bus:</p>
  
  <pre><code>Command #     Command Class   id          amount
  ---------     -------------   -------     -------------
  1             IssueCmd        QP34        123.45
  2             RedeemCmd       QP34        38.10
  </code></pre>
  
  <p>When processing the first command, the CommandHandler (CH) for <code>IssueCmd</code> will put an <code>IssuedEvt</code> object on the event bus. The event will be processed by the EventSourcingHandler (ESH) for the <code>IssuedEvt</code>. We'll then have an instance of <code>GiftCard</code> with <code>id</code> set to "<em>QP34</em>" and <code>remainingValue</code> set to <em>123.45</em>.</p>
  
  <p>When processing the second command, the CH for <code>RedeemCmd</code> will put a <code>RedeemedEvt</code> object on the event bus. The event will be processed by the ESH for the <code>RedeeemedEvt</code>. We'll then have an instance of <code>GiftCard</code> with <code>id</code> set to "<em>QP34</em>" and <code>remainingValue</code> set to <em>85.35</em>.</p>
  
  <p><strong>QUESTION: After each event is handled by its designated ESH, how and where does the resulting object instance persist?</strong></p>
  
  <p>Previously, the answer I've heard is: it really doesn't. All that persists are the event objects, and those are kept in Axon's event store. When an object's current state is needed, Axon tells the command model to initiate an instance of the <code>GiftCard</code> class and events are applied to it from the earliest to the latest. This is the definition of Event Sourcing.</p>
  
  <p>But, when Event Sourcing, after the <code>IssuedEvt</code> is processed, the <em>123.45</em> in <code>remainingValue</code> has to be persisted somewhere in order for the ESH for the <code>RedeemedEvt</code> to have the correct value for its subtraction operation.</p>
  
  <p><strong>How and where is the object state persisted between calls to the ESHs?</strong></p>