Hi,
I’m new to Axon, so this may well be my issue, but I can’t see the way out.
I have an aggregate (eg “Account”) where creating a new instance via a @CommandHandler annotated constructor applies two events (eg “AccountCreatedEvent” and “AccountInvoiceGeneratedEvent”). The code (kotlin) is pretty unremarkable:
@CommandHandler
constructor**(command: CreateAccountCommand)** : this**() {**
val accountId = identifierFactory.generateIdentifier**()**
apply**(AccountCreatedEvent(**id = accountId,
name = command.name))
val invoiceId = identifierFactory.generateIdentifier**()**
apply**(AccountInvoiceCreatedEvent(**accountId = accountId,
invoiceId = invoiceId**))**
}
When testing this, I’m getting:
org.axonframework.eventsourcing.eventstore.EventStoreException:
Writing events for an unexpected aggregate. This could indicate that a wrong aggregate is being triggered.
Debugging the AggregateTestFixture code, the issue comes from the first event (the constructor) not having an aggregate identifier (which kind of makes sense - it doesn’t exist yet) but the second event does. The code checks:
if (!lastEvent.getAggregateIdentifier**().equals(event.getAggregateIdentifier())) {**
where “lastEvent” is the AccountInvoiceGeneratedEvent, and “event” is the AccountCreatedEvent.
I’m not sure if it’s a bug where the null check at AggregateTestFixture.java should also be checking for an empty string (getAggregateIdentifier() for AccountCreatedEvent returns an empty string rather than null) or am I doing something wrong?
Thanks,
Martin