question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Commands routed to the parent of polymorphic aggregates cause IncompatibleAggregateException

See original GitHub issue

Basic information

Steps to reproduce

Using polymorphic aggregates, send a first command to create the child aggregate, then send a command targeting a CommandHandler declared in the parent class.

Expected behaviour

Before 4.6.0, no exception were raised and the command handler was successfully called.

Actual behaviour

Since 4.6.0, an IncompatibleAggregateException is raised.

The behavior is reproduced in the github repository, here is the stacktrace :

org.axonframework.eventsourcing.IncompatibleAggregateException: Aggregate identifier must be non-null after applying an event. Make sure the aggregate identifier is initialized at the latest when handling the creation event. at org.axonframework.eventsourcing.EventSourcedAggregate.publish(EventSourcedAggregate.java:256) ~[axon-eventsourcing-4.6.0.jar:4.6.0] at org.axonframework.eventsourcing.EventSourcedAggregate$$Lambda$1660.0000000000000000.accept(Unknown Source) ~[na:na] at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) ~[na:na] at org.axonframework.eventsourcing.EventSourcedAggregate.lambda$initializeState$0(EventSourcedAggregate.java:284) ~[axon-eventsourcing-4.6.0.jar:4.6.0] at org.axonframework.eventsourcing.EventSourcedAggregate$$Lambda$1657.0000000000000000.accept(Unknown Source) ~[na:na] at org.axonframework.modelling.command.inspection.AnnotatedAggregate.lambda$execute$2(AnnotatedAggregate.java:349) ~[axon-modelling-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.inspection.AnnotatedAggregate$$Lambda$1658.0000000000000000.run(Unknown Source) ~[na:na] at org.axonframework.modelling.command.AggregateLifecycle.lambda$execute$0(AggregateLifecycle.java:189) ~[axon-modelling-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.AggregateLifecycle$$Lambda$1659.0000000000000000.call(Unknown Source) ~[na:na] at org.axonframework.messaging.Scope.executeWithResult(Scope.java:111) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.AggregateLifecycle.execute(AggregateLifecycle.java:188) ~[axon-modelling-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.inspection.AnnotatedAggregate.execute(AnnotatedAggregate.java:349) ~[axon-modelling-4.6.0.jar:4.6.0] at org.axonframework.eventsourcing.EventSourcedAggregate.initializeState(EventSourcedAggregate.java:281) ~[axon-eventsourcing-4.6.0.jar:4.6.0] at org.axonframework.eventsourcing.EventSourcingRepository.doLoadAggregate(EventSourcingRepository.java:156) ~[axon-eventsourcing-4.6.0.jar:4.6.0] at org.axonframework.eventsourcing.EventSourcingRepository.lambda$doLoadWithLock$1(EventSourcingRepository.java:136) ~[axon-eventsourcing-4.6.0.jar:4.6.0] at org.axonframework.eventsourcing.EventSourcingRepository$$Lambda$976.000000005F7542F0.get(Unknown Source) ~[na:na] at org.axonframework.tracing.Span.runSupplier(Span.java:134) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.eventsourcing.EventSourcingRepository.doLoadWithLock(EventSourcingRepository.java:136) ~[axon-eventsourcing-4.6.0.jar:4.6.0] at org.axonframework.eventsourcing.EventSourcingRepository.doLoadWithLock(EventSourcingRepository.java:55) ~[axon-eventsourcing-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.LockingRepository.doLoad(LockingRepository.java:137) ~[axon-modelling-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.LockingRepository.doLoad(LockingRepository.java:60) ~[axon-modelling-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.AbstractRepository.lambda$null$6(AbstractRepository.java:141) ~[axon-modelling-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.AbstractRepository$$Lambda$946.000000005F7133C0.apply(Unknown Source) ~[na:na] at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1133) ~[na:na] at org.axonframework.modelling.command.AbstractRepository.lambda$load$8(AbstractRepository.java:140) ~[axon-modelling-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.AbstractRepository$$Lambda$945.000000005F6F6C20.get(Unknown Source) ~[na:na] at org.axonframework.tracing.Span.runSupplier(Span.java:134) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.AbstractRepository.load(AbstractRepository.java:137) ~[axon-modelling-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.AggregateAnnotationCommandHandler$AggregateCommandHandler.handle(AggregateAnnotationCommandHandler.java:561) ~[axon-modelling-4.6.0.jar:4.6.0] at org.axonframework.modelling.command.AggregateAnnotationCommandHandler$AggregateCommandHandler.handle(AggregateAnnotationCommandHandler.java:550) ~[axon-modelling-4.6.0.jar:4.6.0] at org.axonframework.messaging.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:57) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.messaging.interceptors.CorrelationDataInterceptor.handle(CorrelationDataInterceptor.java:67) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.messaging.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:55) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.commandhandling.SimpleCommandBus$$Lambda$1225.0000000000000000.call(Unknown Source) ~[na:na] at org.axonframework.messaging.unitofwork.DefaultUnitOfWork.executeWithResult(DefaultUnitOfWork.java:77) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.commandhandling.SimpleCommandBus.lambda$handle$3(SimpleCommandBus.java:198) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.commandhandling.SimpleCommandBus$$Lambda$858.000000005E701000.run(Unknown Source) ~[na:na] at org.axonframework.tracing.Span.run(Span.java:72) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.commandhandling.SimpleCommandBus.handle(SimpleCommandBus.java:189) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.commandhandling.SimpleCommandBus.doDispatch(SimpleCommandBus.java:163) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.commandhandling.SimpleCommandBus.dispatch(SimpleCommandBus.java:130) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.commandhandling.gateway.AbstractCommandGateway.send(AbstractCommandGateway.java:76) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.commandhandling.gateway.DefaultCommandGateway.send(DefaultCommandGateway.java:83) ~[axon-messaging-4.6.0.jar:4.6.0] at org.axonframework.commandhandling.gateway.DefaultCommandGateway.sendAndWait(DefaultCommandGateway.java:100) ~[axon-messaging-4.6.0.jar:4.6.0] at com.example.apas.BugSample.run(BugSample.java:52) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:344) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:229) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:166) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.boot.context.event.EventPublishingRunListener.ready(EventPublishingRunListener.java:114) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplicationRunListeners.lambda$ready$6(SpringApplicationRunListeners.java:82) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplicationRunListeners$$Lambda$853.000000005F557250.accept(Unknown Source) ~[na:na] at java.base/java.util.ArrayList.forEach(ArrayList.java:1540) ~[na:na] at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplicationRunListeners.ready(SpringApplicationRunListeners.java:82) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:323) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.5.jar:2.7.5] at com.example.apas.AxonPolymorphicAggregateSampleApplication.main(AxonPolymorphicAggregateSampleApplication.java:10) ~[classes/:na]

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
smcvbcommented, Nov 2, 2022

Happy to hear that, @raphael-jungers! I will reopen the issue for a bit, until the PR is merged. If that’s okay with you, of course.

1reaction
raphael-jungerscommented, Nov 2, 2022

Thank you for the quick reply and the bug fix @smcvb ! The fix does work on our real project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Axon Framework - Release 4.6.2 - Announcements
... Commands routed to the parent of polymorphic aggregates cause IncompatibleAggregateException #2464; Fixes the saga list injection bug, ...
Read more >
Releases · AxonFramework/AxonFramework - GitHub
... Commands routed to the parent of polymorphic aggregates cause IncompatibleAggregateException #2464; Fixes the saga list injection bug, issue 2462.
Read more >
Aggregate identifier must be non-null after applying an event ...
The problem is that your update command is defined as a constructor. The command should go to the already existing aggregate instance.
Read more >
Multi-Entity Aggregates in Axon - Baeldung
We can use the CommandHandler annotation inside an entity to directly route these commands to the appropriate entity. As Event Sourcing is used, ......
Read more >
Commanded.Aggregates.Aggregate – Commanded v0.16.0
Aggregate is a GenServer process used to provide access to an instance of an event sourced aggregate. It allows execution of commands against...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found