Deleted Aggregates

Hi all,

As a repository has no concept of deleting an aggregate (only adding &
loading) it's necessary to add some action in the domain object if
someone tries to load a deleted aggregate again.

How do you handle deleted Aggregates?

I added a simple boolean "deleted" field and then all methods check
for deletion before executing.

Any better solutions?


If you use EventSourcing, you can use the AggregateDeletedEvent as a marker interface. If the repository encounters such an event when loading an aggregate, it will throw an AggregateDeletedException (which extends AggregateNotFoundException). See chapter 4.1.1 in the documentation (

For regular repositories, it’s is probably best to implement a delete method. Currently there is none on the GenericJpaRepository. It might be a good idea to add one there. Thinking about it, I might even add an interface for special “delete-aware” repositories.



Hi Michael,

Just apply an event which implements the AggregateDeletedEvent marker interface. If you do try to load the aggregate from the repository you will receive an AggregateDeletedException.


Hi Allard & Seamus,

Thanks for the hint. I looked at the sample but I didn't recognize the
marker interface :wink:

@Allard:The "Delete Aware" repository interface sounds good.