IncompatibleAggregateException when running tests


I am writing an application using the axon framework. Everything is working fine, exept the tests.

When I run the tests (using either ‘mvn test’ or running from the IDE) I get the following error:

IncompatibleAggregateException: Aggregate identifier must be non-null after applying an event. Make sure the aggregate identifier is initialized at the latest when handling the creation event.

After searching the web I couldn’t find a solution to this problem.

I created a quickstart project here that shows the error.

Am I missing something or is this a bug?


Hi Thomas,

The idea is to update the state of aggregates in event handlers, and not in command handlers, so that when an aggregate needs to be restored, it can recreate its state.
So, in your example, add 2 event sourcing handlers to the product class, that update the state and remove the state updates from the command handlers, like this:

   public Product(CreateProductCommand command) {
      //this.partNumber = command.getPartNumber();
      apply(new ProductCreatedEvent(command.getPartNumber()));

   public void handle(EditProductTextsCommand command) {
// = command.getName();
//    this.description = command.getDescription();
      apply(new TextsEditedEvent(command.getName(), command.getDescription()));

   public void on(ProductCreatedEvent event) {
      this.partNumber = event.getPartNumber();

   public void on(TextsEditedEvent event) { = event.getName();
      this.description = event.getDescription();


Thank you! I should read the reference guide again. :slight_smile:

Hi Thomas,

a slight nuance, here. Marc’s comment is assuming you’d want to use Event Sourcing, which is also the assumptions the tests make.
For example, in your fixture, you have “fixture.given(new ProductCreatedEvent(PART_NUMBER))”. Your aggregate will have to define what that means to it in terms of state changes.

In itself, the aggregate doesn’t have to be wrong, the way you defined it. It just can’t be event sourced in its current form. Note that the test fixtures provided by Axon currently only support event sourced aggregates.