issue when upgrading to Axon 3.2 and Spring Boot 2.0

Hi all,

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

Shouldn’t the globalIndex be annotated as such

strategy= GenerationType.AUTO,
name = “native”,
strategy = “native”
private long globalIndex;

as explained here?

Hi Mario,

you are right in that this would be the best configuration to have (using JPA annotations instead of Hibernate specific ones). Unfortunately, we couldn’t because we would break backwards compatibility with our existing releases.

We do recommend configuring sequences explicitly (for other databases than MySQL), using an orm.xml file. Unfortunately, there is not one configuration that plays well with all databases out there. Therefore, we have left all the default settings. This may result in suboptimal implementations for some, but at least it will always work. Unfortunately, as the defaults have changed between Hibernate releases, this breaks backwards compatibility when migrating.

Once we allow ourselves to break with our past, we will change the structure of the GeneratedValue annotations.