Entering content frame

Function documentation One-to-Many Bidirectional Relationships Locate the document in its SAP Library structure

Use

In a one-to-many bidirectional relationship, a field of type java.util.Set on the one-side corresponds to a field of persistence capable type on the many-side of the relationship. The element type of the set on the one-side is the same as the persistence capable class type on the many-side; the type of the field on the many-side is the type of the persistence capable class on the one-side. In the relational model there is a foreign key column on the many-side table referring to primary key columns in the one-side table.

 

Example

There is a one-to-many relationship between class example.jdo.Manager and class example.jdo.Employee. The class Manager has a relationship field set of type java.util.Set that contains elements of type Employee. The class Employee has a relationship field ref of type Manager. The class Manager is mapped to table TMP_MANAGER; the class Employee is mapped to table TMP_EMPLOYEE. In table TMP_EMPLOYEE there is a foreign key column MANAGER with primary key column MANID in table TMP_MANAGER. In the mapping metadata, there is a foreign key element for both relationship fields set and refcontaining the same foreign key (identified by the foreign key name). In the relationship field element for the field set, the property update must be set to false.

 

This graphic is explained in the accompanying text

 

The XML metadata has the following contents:

 

<jdo>

  <package name="example.jdo">

    <class name="Manager" identity-type="application" objectid-class="Manager$Id">

      <field name="manid" persistence-modifier="persistent" primary-key="true"/>

      <field name="set" persistence-modifier="persistent"

          embedded="false" default-fetch-group="false">

        <collection element-type="Employee" embedded-element="false"/>

      </field>

    </class>

    <class name="Employee" identity-type="application" objectid-class="Employee$Id">

      <field name="empid" persistence-modifier="persistent" primary-key="true"/>

      <field name="ref" persistence-modifier="persistent"

        embedded="false" default-fetch-group="false"/>

    </class>

  </package>

</jdo>

 

<map version="1.0">

  <package name="example.jdo">

    <class name="Manager">

      <field name="manid">

        <column name="MANID" table="TMP_MANAGER"/>

      </field>

      <relationship-field name="set" multiplicity="many" update="false">

        <foreign-key name="EMPLOYEE_TO_MANAGER"

            foreign-key-table="TMP_EMPLOYEE"

            primary-key-table="TMP_MANAGER">

          <column-pair foreign-key-column="MANAGER" primary-key-column="MANID"/>

        </foreign-key>

      </relationship-field>

    </class>

    <class name="Employee">

      <field name="empid">

        <column name="EMPID" table="TMP_EMPLOYEE"/>

      </field>

      <relationship-field name="ref" multiplicity="one">

        <foreign-key name="EMPLOYEE_TO_MANAGER"

            foreign-key-table="TMP_EMPLOYEE"

            primary-key-table="TMP_MANAGER">

          <column-pair foreign-key-column="MANAGER" primary-key-column="MANID"/>

        </foreign-key>

      </relationship-field>

    </class> 

  </package>

</map>

 

 

Leaving content frame