My company uses Axon framework in our internal systems in combination with spring boot.
We are in the process of upgrading to Axon 3.2 (latest release at the time of writing).
The upgrade went well and no issues were detected with Spring Boot 1.5.4.RELEASE.
As soon as we upgraded to Spring Boot 2.0.0.RELEASE we noticed some failures in some of our integrations tests.
Those tests trigger the generations of a number of events upon which assertions are made.
Assertions are now failing since no events are generated. After some debugging sessions we found that the insertions of events in the domain_event_entry table failed with a primary key constraint violation.
In particular this method org.axonframework.eventsourcing.eventstore.jpa.JpaEventStorageEngine#appendEvents failed on entityManager().flush()
The exceptions thrown is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘1’ for key ‘PRIMARY’
After investigating further we have noticed that AbstractSequencedDomainEventEntry#globalIndex is annotated with @GeneratedValue without specifying the strategy.
According to HHH-11014 Hibernate, from version 5.0.x, picks as default behavior of the generation strategy (AUTO) the TABLE generator instead of IDENTITY when the underlying database does not support sequences (MySql in our case) and this caused the misbehavior in our test cases.
The fix eventually was quite simple. We just had to switch to native id generation by setting the following property to false spring.jpa.properties.hibernate.id.new_generator_mappings=false.
Shouldn’t the globalIndex be annotated as such
name = “native”,
strategy = “native”
private long globalIndex;
as explained here?