Annotation Interface EntityId


Marks a property (field or getter) as the unique identifier of an entity or independently stored model.

The presence of this annotation enables automatic routing of updates to the correct entity instance inside an aggregate, based on identifier matching.

This is particularly important in aggregates that consist of nested entities, e.g.: a Project containing a list of Task entities. The framework uses the @EntityId-annotated property to match update messages with their corresponding entity.

You can annotate either a field or its getter method. Optional affixes only affect the persisted identifier and repository lookups; the property itself retains its functional value. They wrap any repository prefix already supplied by an Id. For example, an ID whose repository value is connection-123 combined with @EntityId(prefix = "move-") is stored as move-connection-123.

A one-to-one companion model may use the same property as both its @EntityId and a Parent. The functional property value then identifies the parent relationship, while these affixes still give the companion its own globally unique repository identity.

A model whose functional identifier is unique only below its parent can set parentScoped() to true. Its persisted identity then combines the one non-null declared Parent with the functional identifier. The model property keeps the functional value and graph-local Graph.find(Object, Class) lookup therefore remains natural. Parent-scoped identity is intended for parent-owned values: moving such a model to a different parent changes its persisted identity.

Domain lifecycle determines whether a value should be an independent model; identity is supporting evidence rather than a separate modeling gate. If a child can be created, changed, retained, or deleted independently but has no globally unique functional ID, keep it as a model and use a typed or parent-scoped identifier instead of embedding it as a Member merely for storage convenience.

See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether the persisted model identity is scoped by its one non-null declared parent.
    Postfix added outside the identifier's own repository representation.
    Prefix added outside the identifier's own repository representation.
  • Element Details

    • prefix

      String prefix
      Prefix added outside the identifier's own repository representation.
      Default:
      ""
    • postfix

      String postfix
      Postfix added outside the identifier's own repository representation.
      Default:
      ""
    • parentScoped

      boolean parentScoped
      Whether the persisted model identity is scoped by its one non-null declared parent.
      Default:
      false