When I put a commandhandler in a entity raise exception

When I put a commandhandler in a entity raise exception

Someone can guide me where the problem is?

A probable cause for the wrong chain of events is an exception that occurred while handling the command.
java.lang.NullPointerException
at org.axonframework.commandhandling.model.inspection.AggregateMemberAnnotatedChildEntityCollectionDefinition.lambda$createChildDefinition$5(AggregateMemberAnnotatedChildEntityCollectionDefinition.java:86)

**Entity**
public class LearnProjectSection {
.....

    @EntityId
    private UUID sectionId;
.....

I think an exception can only be thrown there if the field value is null (as opposed to an empty set). Can you confirm this is the case?
Obviously, it should be able to cope with a null value a bit nicer.

Allard

Thank allard .

  1. changed code and solved that exception but raise new exception

  2. A probable cause for the wrong chain of events is an exception that occurred while handling the command.java.lang.IllegalStateException: Aggregate cannot handle this command, as there is no entity instance to forward it to.1.

  3. Is there any reference or sample for how to use complex aggregate root ?


@AggregateMember(type = LearnProjectSection.class)
private Collection<LearnProjectSection> projectSections = new LinkedList<>();

hamid

Hi Hamid,

the problem is that there is currently no entity in the “projectSections” collection that can handle the command you’re sending.
Are you sure a “LearnProjectSectionCreatedEvent” was raised earlier? Axon will also route commands to the correct instance based on the @EntityId. In your case, the command should contain a “getSectionId” that returns a UUID that is equal to one of the "sectionId"s of your entities.
If Axon can’t find a suitable entity, it will raise an “IllegalStateException”.

Cheers,

Allard

Hi

when use @AggregateMember as class you must override equals


@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    LearnProjectSection other = (LearnProjectSection) o;

    return this.getSectionId().equals(other.sectionId);
}