Skip to content
Advertisement

aggregate not found in the event store

I am trying to add data using CQRS framework AXON. But while hitting the API(used to add an order). I am getting the below error:-

JavaScript

But i already have an Aggregate in my code(OrderAggregate.Java).

The Full code can be found at – https://github.com/iftekharkhan09/OrderManagementSystem

API to add Order – http://localhost:8080/confirmOrder

Request Body:-

JavaScript

Can anyone please tell me where am i doing wrong? Any help is appreciated!

Advertisement

Answer

For other readers, let me share the Aggregate you’ve created in your repository:

JavaScript

There are several things you can remove entirely from this Aggregate, which are:

  1. The OrderRepositoryData
  2. The OrderAggregate constructor which sets the OrderRepositoryData
  3. The manually saving of an Order in the @EventSourcingHandler annotated function

What you’re doing here is mixing the Command Model’s concern of making decisions with creating a queryable Order for the Query Model. It would be better to remove this logic entirely from an Aggregate (the Command Model in your example) and move this to an Event Handling Component.

This is however not the culprit for the AggregateNotFoundException you’re receiving. What you’ve missed is to make the CreateOrderCommand command handler a constructor.

The CreateOrderCommand will create an Order, as it’s name already suggests. Hence, it should be handled by a constructor rather than a regular method. So, instead of this:

JavaScript

You should be doing this:

JavaScript

Hope this helps you out @Sunny!

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement