Sending multiple commands to the same aggregate

If i send multiple commands to the same aggregate then only the first is handled.
Is this a configuration problem or am i missing something?

The message i am getting after the 2nd command is send:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.axonframework.commandhandling.CommandExecutionException: Cannot invoke “Object.hashCode()” because “key” is null

The service method here i do my sending of the command is:

   public void maakAanvraag() {
        UUID aanvraagId = UUID.randomUUID();

        commandGateway.sendAndWait(
                VerwerkAanvraag.builder()
                        .aanvraagId(aanvraagId)
                        .build()
        );

        commandGateway.sendAndWait(
                VerwerkPersoonsgegevensVastgesteld.builder()
                        .aanvraagId(aanvraagId)
                        .build()
        );
        
        commandGateway.sendAndWait(
                VerwerkOrganisatiegegevensVastgesteld.builder()
                        .aanvraagId(aanvraagId)
                        .organisatieId(organisatieView.getOrganisatieId())
                        .rolOrganisatie(rolOrganisatie)
                        .build()
        );

        commandGateway.sendAndWait(
                VerwerkBeperkingErkenningsdoelGematcht.builder()
                        .aanvraagId(aanvraagId)
                        .build());
    }

My aggregate is:

@Aggregate
@Getter
@NoArgsConstructor
public class Aanvraag {

    public static final String META_DATA_ZAAKNUMMER = "aanvraag_zaaknummer";

    @AggregateIdentifier
    private UUID aanvraagId;

    @CommandHandler
    public Aanvraag(VerwerkAanvraag command) {
        AanvraagGeregistreerd aanvraagGeregistreerd =
                AanvraagGeregistreerd.builder()
                        .aanvraagId(command.getAanvraagId())
                        .build();

        apply(aanvraagGeregistreerd, MetaData.with(META_DATA_ZAAKNUMMER, "123456789"));
    }

    @EventSourcingHandler
    public void on(AanvraagGeregistreerd event) {
        aanvraagId = event.getAanvraagId();
    }

    @CommandHandler
    public void verwerkOrganisatiegegevensVastgesteld(VerwerkOrganisatiegegevensVastgesteld command) {
        OrganisatiegegevensVastgesteld persoonsgegevensVastgesteld =
                OrganisatiegegevensVastgesteld.builder()
                        .aanvraagId(command.getAanvraagId())
                        .build();
        apply(persoonsgegevensVastgesteld);
    }

    @EventSourcingHandler
    public void on(OrganisatiegegevensVastgesteld event) {
        aanvraagId = event.getAanvraagId();
    }

    @CommandHandler
    public void verwerkPersoonsgegevensVastgesteld(VerwerkPersoonsgegevensVastgesteld command) {
        PersoonsgegevensVastgesteld persoonsgegevensVastgesteld =
                PersoonsgegevensVastgesteld.builder()
                        .aanvraagId(command.getAanvraagId())
                        .build();
        apply(persoonsgegevensVastgesteld);
    }

    @EventSourcingHandler
    public void on(PersoonsgegevensVastgesteld event) {
        aanvraagId = event.getAanvraagId();
    }

    @CommandHandler
    public void verwerkBeperkingErkenningsdoelGematcht(VerwerkBeperkingErkenningsdoelGematcht command) {
        BeperkingErkenningsdoelGematcht beperkingErkenningsdoelGematcht =
                BeperkingErkenningsdoelGematcht.builder()
                        .aanvraagId(command.getAanvraagId())
                        .build();
        apply(beperkingErkenningsdoelGematcht);
    }

    @EventSourcingHandler
    public void on(BeperkingErkenningsdoelGematcht event) {
        aanvraagId = event.getAanvraagId();
    }
}

The project uses Spring Boot 2.6.6 with axon-spring-boot-starter 4.5.9

What do your command implementations look like? Could you share their code too?
It look like your are missing the @TargetAggregateIdentifier at command level…

1 Like

I might be wrong, but is this a duplicate of this StackOverflow issue, @Jan?
If so, as you replied there, the solution you spotted is as follows:

We solved the problem. Issue had nothing to do with Axon. The problem was an Logging interceptor.
After removing this log interceptor the Axon worked as expected.

I still have a response based on that though.
Axon Framework also as a LoggingInterceptor, but I am guessing that’s not the component that caused the predicament.
Could you enlighten us a bit further on what kind of LoggingInterceptor caused this problem, and why? Thanks!

@Steven_van_Beelen yes, this is the same as on StackOverflow.