Concurrent Modification Exception when creating an Aggregate Repository Bean on a subclassed Aggregate.

Hey all,

I am working in Axon 3(a little behind, but we’re a big company and it’s been difficult to upgrade our axon versions) and Spring 2.

I’m running into an issue with creating a base aggregate, and extending it.

@Aggregate
public abstract class BaseTokenizationAggregate {
}

@EqualsAndHashCode(callSuper = true)
public class TokenizationAggregate extends BaseTokenizationAggregate {
}

then creating an aggregate factory in our config

@Bean
public AggregateFactory<TokenizationAggregate> aggregateFactory(ApplicationContext context) {
GenericAggregateFactory<TokenizationAggregate> factory = new GenericAggregateFactory<>(TokenizationAggregate.class);
return factory;
}

@Bean(name = "tokenizationAggregateRepository")
public EventSourcingRepository<TokenizationAggregate> tokenizationAggregateRepository(AggregateFactory<TokenizationAggregate> aggregateFactory, SnapshotTriggerDefinition trigger, ParameterResolverFactory parameterResolverFactory, EventStore eventStore, LockFactory lockManager) {
failure happens here -----> return new EventSourcingRepository<>(aggregateFactory, eventStore, lockManager, parameterResolverFactory, trigger);
}

My aggregate repository is throwing a concurrent modification exception with this stack trace:

Caused by: java.util.ConcurrentModificationException at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134) at org.axonframework.messaging.annotation.AnnotatedHandlerInspector.createInspector(AnnotatedHandlerInspector.java:79) at org.axonframework.messaging.annotation.AnnotatedHandlerInspector.inspectType(AnnotatedHandlerInspector.java:71) at org.axonframework.commandhandling.model.inspection.ModelInspector.inspectAggregate(ModelInspector.java:88) at org.axonframework.commandhandling.model.AbstractRepository.<init>(AbstractRepository.java:74) at org.axonframework.commandhandling.model.LockingRepository.<init>(LockingRepository.java:95) at org.axonframework.eventsourcing.EventSourcingRepository.<init>(EventSourcingRepository.java:156) at fitpay.discover.spring.config.AxonConfigurationProduction.tokenizationAggregateRepository(AxonConfigurationProduction.java:90) at fitpay.discover.spring.config.AxonConfigurationProduction$$EnhancerBySpringCGLIB$$b64a5d26.CGLIB$tokenizationAggregateRepository$4(<generated>) at fitpay.discover.spring.config.AxonConfigurationProduction$$EnhancerBySpringCGLIB$$b64a5d26$$FastClassBySpringCGLIB$$5bd8de6d.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) at fitpay.discover.spring.config.AxonConfigurationProduction$$EnhancerBySpringCGLIB$$b64a5d26.tokenizationAggregateRepository(<generated>) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ... 34 more

Is there something else I need to do to setup this aggregate hierarchy? In Axon 2 we simply extended the AbstractAnnotatedAggregateRoot, but that is no longer available in 3. Are there any examples of this I can look at somewhere?

Hi Leif,

I am pretty sure this question is a duplicate of this user group question, the only difference being the title, which here refers to the Aggregate Repository and in the other question refers to the Aggregate Factory.

The answer between these two wont differ, so I suggest anybody looking for a solution to track the question I just referred too.

Cheers,
Steven