Annotation Interface EntityMember


@Documented @Target({FIELD,METHOD,ANNOTATION_TYPE}) @Retention(RUNTIME) public @interface EntityMember
Annotation placed on fields or methods of an entity that should be treated as a child entity.

Messages are filtered based on the eventTargetMatcher() and commandTargetResolver(), which both default to a matcher based on the routingKey(). The default routing key matcher and resolver will match a property on the child entity and the message that matches the routingKey() attribute.

The routingKey() property is required whenever there are several child entities of the same type within a class. Hence, it is required when a collection of child entities is used. However, it also applies when several singular child entity fields of the same type exist within an entity. For purely singular child entities (not backed by an Iterable nor reoccurring within the class), this can be omitted.

Note that this annotation existed as org.axonframework.modelling.command.AggregateMember before version 5.0.0. Besides the change in name to align better with the entities instead of aggregates, the version introduced the commandTargetResolver(), which before was not configurable.

Since:
3.0.0
Author:
Allard Buijze, Mitchell Herrijgers
  • Element Details

    • routingKey

      String routingKey
      The routing key to use for matching messages with this child entity.

      This attribute is required whenever there are several child entities of the same type. For example, when a collection of child entities is used.

      Defaults to an empty string, which means no matching will take place.

      Returns:
      the routing key to use for matching messages to this child entity
      Default:
      ""
    • eventTargetMatcher

      Class<? extends EventTargetMatcherDefinition> eventTargetMatcher
      The EventTargetMatcher is used to determine which entity should be evolved by the EventMessage.

      The forwarding mode can match 0, 1, or multiple child entities, and as such functions like a predicate or filter.

      Defaults to using the RoutingKeyEventTargetMatcher, which matches messages based on the routingKey(). Users can choose to create their own definition, with their own forwarding mode, that has specific routing logic.

      Returns:
      the class defining the EventTargetMatcher for this child entity
      Default:
      org.axonframework.modelling.entity.annotation.RoutingKeyEventTargetMatcherDefinition.class
    • commandTargetResolver

      Class<? extends CommandTargetResolverDefinition> commandTargetResolver
      The CommandTargetResolverDefinition is used to determine to which of the child entities a CommandMessage should be forwarded.

      The result should always be a single child entity, or no child entity at all, as a command can only be handled by a single entity.

      The result can also be null to indicate that no child entity should handle the command. This allows users to declare multiple fields with the same child entity type, but with different routing key properties, with different routing logic for commands.

      Defaults to using the RoutingKeyCommandTargetResolverDefinition, which matches messages based on the routingKey(). Users can choose to create their own definition, with their own forwarding mode, that has specific routing logic.

      Returns:
      the class defining CommandTargetResolver for this child entity
      Default:
      org.axonframework.modelling.entity.annotation.RoutingKeyCommandTargetResolverDefinition.class