ConcurrencyException: OUT_OF_RANGE sequence number: 0, expecting: 1

I’m working on a trivial create / update example using the AxonIQ EventStore. My create functionality works 100%. Update mostly works (read model gets updated) but I get this in my output and logs:

{“timestamp”:1512549981707,“status”:500,“error”:“Internal Server Error”,“exception”:“org.axonframework.commandhandling.model.ConcurrencyException”,“message”:“OUT_OF_RANGE: [AXONIQ-2000] Invalid sequence number: 0 for aggregateId: f73d46d6-644e-4022-aa49-55bf886fd6f9 expecting: 1”,“path”:"/status-type/f73d46d6-644e-4022-aa49-55bf886fd6f9"}

The sequence number is not being incremented. I thought this happened transparently behind the scenes?

Steps:

  1. Create a new thing (generates new aggregate id)
  2. Try to update the thing (using same aggregate id)

I have distinct Create and Update events.

Any suggestions?

From looking at this more, it appears the the EventBus part of the AxonIQ EventStore is working fine but the EventStore append is failing because the sequence number isn’t incrementing.

Hi Justin,

this looks like an issue in your setup. Could you share your Aggregate command handlers? Sequence number 0 should only be used for newly created aggregate instances. Once an aggregate is loaded, Axon will automatically increment the sequence number.

The Event Store is just validating that you’re using “legal” sequence numbers. It won’t generate them for you.

Cheers,

Allard

I think I must be missing the “once an aggregate is loaded part” on my update/delete.

Here is a sample Aggregate: https://pastebin.com/1AJ8h8YX

My goal is to get a very basic CRUD example working so I understand how the Axon plumbing works.

thx
Justin

Hi Justin,

exactly what I thought: both your @CommandHandler methods are constructors. Your update command is probably expected to be executed on an existing aggregate, not on a freshly created one. In that case, make it a regular method.

Cheers,

Allard

THANK-YOU so much Allard. I am now up and running.