Duplicated primary key on domainevententry

Hi,

From time to time I get this exception:

Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint “domainevententry_pkey”
Detail: Key (id)=(6642) already exists.

It seems like ‘sequence’ relation is not correctly updated.

Why this can happen?

Thank you

Cheers

Hi,

which version of Axon are gou using?
PK violations normally only occur when you have multiple VM’s attemptong to concurrently processing the same aggregate. In such a case, it is always safe to reattempt the failing command.
On the JPAEventStore, you can set the DataSource, which is used to identify the error codes that represent a key violation. Commands will still fail, but with an exception that will make clear what’s going wrong. Some Axon mechanisms (in Axon 2) will automatically reattempt the command.

Cheers,

Allard

Hi Allard

I’m using Axon 1.4 and EclipseLink as an ORM framework. From axon sources I saw AbstractEventEntity has id attribute annotated with @GeneratedValue. In EclipseLink, this will use default strategy by creating ‘sequence’ table. I will try to use another strategy for integer auto increment generation, to see if problem can be due table strategy.

Cheers

Hi,

if the duplicate key violation is about the ID, that must mean that the database (or EclipseLink) mechanism isn’t generating unique values for different clients. Unfortunately, there is not much Axon can do about that.
Note that Axon 2 doesn’t use autogenerated keys anymore. That means the problem cannot occur there. Not for this reason, at least.

Cheers,

Allard