Defining relationships in your abstract persistence schema (in the DD)

CMP field definitions are so easy. You declare a <cmp-field> and give it a name that matches one of your getter/setter pairs (following the naming rule of dropping the “get” and “set” and beginning the CMP field name with a lower-case letter).

But CMR is more involved. You can’t be in a relationship with only yourself, so a relationship always includes two beans!

  1. Define an ejb-relation between two beans

    Note

    Every relationship has exactly two beans.

    1. Define an ejb-relationship-role for one bean

      1. multiplicity for this bean

        Note

        Multiplicity of this bean (i.e. how many of this type will the OTHER participant have)

      2. source for this bean

        Note

        Which bean are we really talking about?

      3. cmr-field for this bean

        Note

        Must match the “virtual field” in the bean class

      4. cascade-delete for this bean

        Note

        Only if THIS bean wants to be deleted when its partner is deleted.

    1. Define an ejb-relationship-role for the second bean

      1. multiplicity for this bean

      2. source for this bean

      3. cmr-field for this bean

      4. cascade-delete for this bean

        Note

        Same stuff for the second participant in the relationship

Relationship definition for the Director-to-Movie relationship

image with no caption
  1. Define an ejb-relation between two beans

    <ejb-relation>

    Note

    Each <ejb-relation> describes one pair of beans... one relationship. They REALLY should have named this <ejb-relationship>

    1. Define an ejb-relationship-role for ...

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.