Adding a new AR with the same id as an existing one

What is supposed to happen when I call Repository.add() and give it a
newly created AR with the same AggregateIdentifier as a previously
added one? I thought I would get an exception. But it looks like it
just takes it.

Am I misunderstanding something?

Hi Per,

when a new aggregate is created with an existing ID, it will generate a DomainEvent with that aggregate identifier and sequence number 0. The repository expects the backing event store to enforce a uniqueness constraint on these two parameters. The repository itself will not enforce any constraints.

Which version are you using, and which event store?



In production code I use the JpaEventStore, but this was with 0.7 and
the test fixture. I haven't tested this in production code yet. So I
guess the RecordingEventStore does not enforce any uniqueness
constraint. I think it should.


I think your assumption is totally correct. It (the RecordingEventStore) should check for a wrong sequence of numbers. The JPA Event Store relies on a uniqueness constraint in the tables, which (if you generated the tables using the JPA Annotations) is there by default.

I’ll create an issue for it in the issue tracker. Thanks for reporting it!