ExpectedVersion?

Axon 0.6 deprecated Repository.load(UUID uuid) in favor of
Repository.load(UUID uuid, long version);

I have a practical question. When I look at the order example from the
jteam blog, this would mean that the OrderCommandHandler must pass the
expectedversion to the reporsitory handling the cancel and confirm
command:

    @CommandHandler

    public void confirmOrder(ConfirmOrderCommand command) {

        Order order = orderRepository.load(new
StringAggregateIdentifier(command.getOrderId()));

        order.confirm();

    }

    @CommandHandler

    public void cancelOrder(CancelOrderCommand command) {

        Order order = orderRepository.load(new
StringAggregateIdentifier(command.getOrderId()));

        order.cancel();

    }

My question is where the heck does it get the version from?
What is the meaning of the expectedVersion?

Jaron

Hi Jaron,

the method has not been removed in 0.7 (and it’s not deprecated there either). The sequence number of the last domain event from an aggregate is the version number of an aggregate. But the fact that you asked this question made me add an explicit getter to the DomainEvent class (getAggregateVersion).

So that’s where you can get it from. In 0.6, you’ll just need to get the sequence number of the event.

The version number of an aggregate is used as an optimistic locking mechanism. With event sourced aggregates, these optimistic locks can also be used to distinguish between conflicting changes and changes that can be safely merged. See org.axonframework.eventsourcing.ConflictResolver

Cheers,

Allard