Commands routed to the parent of polymorphic aggregates cause IncompatibleAggregateException
See original GitHub issueBasic information
- Axon Framework version: 4.6.0 and 4.6.1
- JDK version: 11
- Complete executable reproducer if available (e.g. GitHub Repo): https://github.com/raphael-jungers/axon-polymorphic-aggregate-sample
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:
- Created a year ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
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.
Thank you for the quick reply and the bug fix @smcvb ! The fix does work on our real project.