Cannot reuse aggregate identifier

When i send my first command i have the below error, yet the domainevents table is empty

Cannot reuse aggregate identifier [ExternalId(value=1e4b8fdb-25a4-4cd4-8afe-fe2d10ee95ea)] to create aggregate [PayerAggregate] since identifiers need to be unique.
        externalId = ExternalId(),
        rqUID = request.rqUID,
        phoneNumber = request.phoneNumber

internal class PayerAggregate() {

    private lateinit var externalId: ExternalId

    private val confirmPayerRq = ConfirmPayerRq()

    fun handle(command: ConfirmPayer) {
                externalId = command.externalId,
                rqUID = command.rqUID,
                phoneNumber = command.phoneNumber

data class ConfirmPayer(
    @TargetAggregateIdentifier val externalId: ExternalId,
    val rqUID: String,
    val phoneNumber: String
    val timestamp: Instant =

data class ExternalId(val value: UUID = UUID.randomUUID()) {
    companion object {
        fun of(value: String) = ExternalId(UUID.fromString(value))

    fun asReference() = value.toString()

Hi, could you share the entire stacktrace of the exception you’re getting? I think one of the causes is likely to explain more of what’s going on.

Which database are you using?

I think I saw this error before and it was happening while using H2 DB > 1.4 and hibernate, setting solved the problem

I using mongodb


I don’t get a stacktrace for the exception, i get the message in swagger when i test the api.
I knew the cause of the problem but I don’t know how to solve it.

The problem in the line 39, when i tried to create an instance of XMLGregorianCalendar, when i change dueDate = newXMLGregorianCalendar() to dueDate = null it works fine. demo/Controller.kt at main · akanzari/demo · GitHub

@Steven_van_Beelen you have any idea please ?

It’s odd you’re not getting an exception, as the message you share is simply bound to a AggregateStreamCreationException, ConcurrencyException, or EventStoreException.
This is fixed in the AbstractEventStorageEngine implementation, which you’re definitely using when you have Mongo configured.

In all honesty, I don’t see how this would impact your Event Store’s remark that the Aggregate Identifier should be unique.
The RequestConfirmPayer uses the @TargetAggregateIdenifier annotated field, which is the ExternalId in your code, to set the aggregate identifier on the events to publish.

What might cause issues is the ExternalId itself. Axon Framework expects the aggregate identifiers to have a working toString() method. As it’s a data class, I would expect it to work. But perhaps enforcing this may solve something.
However, without a concrete stack trace, it’s hard to predict where the issue lies.

Might externalId be null? Or what happens, if you try it without lateinit? Have you tried to write a Aggregate Test and is there a similar or other problem?