Duplicate entry with Axon 2?

Hi,

we get an exception ‘Duplicate entry’ for key ‘PRIMARY’.

I just thought this is not possible anymore with Axon 2 anymore. How can I solve that?

Thanks.

Hi,

even in Axon 2, there are a few cases in which this can happen. When an aggregate is being modified on two nodes simultaneously, both nodes may attempt to append the event with the same sequence number. Only the first will succeed. The second will fail with this exception.

The other scenario is when the underlying database (mysql is known to do this) uses a repeatable read isolation level by default. Mysql, for example, uses the state of the database at transaction start to return data in queries. So when the second thread waits for the aggregate to be released, and gets a green light, the database will not show any changes made by the other thread.

The solution to this is to configure the connection (pool) to use read committed instead of the default repeatable read.

Cheers,

Allard