Remove an aggregate from the repository

Hi,

while playing around with axon i wonder why it is not possible to remove an aggregate from the repository again. I suspect this has a conceptual reason but could somebody explain it shortly please?

Thanks

Marcus

Hi Marcus,

deleting is actually possible. I assume you are using a object-relationally mapped aggregate? Deleting is considered a state change like any other. The only difference is that this state change sets the “deleted” flag on an aggregate. When the GenericJpaRepository detects this flag (AggregateRoot.isDeleted() returns true), it will delete it from the repository. If you extend one of Axon’s abstract AggregateRoot classes, you can use “markDeleted()” to mark an aggregate as deleted.

EventSourcing repositories will not delete anything, they just append the events to the event store. When reading an aggregate back in, they will notice the “isDeleted” flag and throw an exception as if the aggregate doesn’t exist.

Hope this helps.
Cheers,

Allard

Hi Allard,

thanks for this detailed explanation.

Regards