[AXONIQ-2000] Invalid sequence number 0 for aggregate

Hi!

I am new in Axon and I need help.
I faced with the problem.
I am trying to develop CRUD for one Entity.
Now I have developed aggreate.

@Aggregate
class UpdatePermission() {
@AggregateIdentifier
private var id: AxxalonIdentifier? = null

@CommandHandler
constructor(command: UpdatePermissionCommand) : this() {
var a = AggregateLifecycle.apply(PermissionUpdateEvent(command.id, command.title))
}

@CommandHandler
constructor(command: CreatePermissionCommand) : this() {
var a = AggregateLifecycle.apply(PermissionCreatedEvent(command.id, command.title))

}

@EventSourcingHandler(payloadType = PermissionUpdateEvent::class)
fun on(event: PermissionUpdateEvent) {
this.id = event.id
}

@EventSourcingHandler(payloadType = PermissionCreatedEvent::class)
fun on(event: PermissionCreatedEvent) {
this.id = event.id
}
}

And I have the problem with the aggregate.

What is wrong? Do I need a saga for create/update/delete entity by command and event?
Thank you very much for advice!

Hi Sergey,

your command handler for UpdatePermissionCommand is (also) a constructor. That tells Axon that, for this command, you want to create a new instance. However, given the name, I suspect you want to update an existing one.

Change that method to a ‘fun’, and it should work.

Cheers,

Allard

1 Like