Entering content frame

Function documentation Multiset Semantics/Collections Locate the document in its SAP Library structure

Use

All of the previous scenarios described in this section refer to mapping sets. For collections and multiset scenarios, a column for the number of duplicates must be added to the foreign key.

Note

It depends on the static Java type (java.util.Set or java.util.Collection) of the relationship field only whether duplicates are allowed, and whether the additional column for the number of duplicates is necessary.

Example

There is a one-to-many unidirectional relationship between class example.jdo.CarOwner and class example.jdo.Car. The class CarOwner has a relationship field col of type java.util.Collection that contains elements of type Car. The class CarOwner is mapped to table TMP_CAROWNER; class Car is mapped to table TMP_CAR. In table TMP_CAR there is a foreign key column OWNER with primary key column COID in table TMP_CAROWNER and a column DUPLICATE with the number of duplicates. In the mapping metadata there is a foreign key element for the relationship field col containing the foreign key. In addition, the relationship field elements for col have a count sub-element that contains the column for the number of duplicates.

 

This graphic is explained in the accompanying text

 

The XML metadata has the following contents:

 

<jdo>

  <package name="example.jdo">

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

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

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

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

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

      </field>

    </class>

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

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

      </class>

  </package>

</jdo>

 

<map version="1.0">

  <package name="example.jdo">

    <class name="CarOwner">

      <field name="coid">

        <column name="COID" table="TMP_CAROWNER"/>

      </field>

      <relationship-field name="col" multiplicity="many">

        <count>

          <column name="DUPLICATE" table="TMP_CAR"/>

        </count>

        <foreign-key name="CAR_TO_CAROWNER"

            foreign-key-table="TMP_CAR" primary-key-table="TMP_CAROWNER">

          <column-pair foreign-key-column="OWNER" primary-key-column="COID"/>

        </foreign-key>

      </relationship-field>

    </class>

    <class name="Car">

      <field name="cid">

        <column name="CID" table="TMP_CAR"/>

      </field>

    </class> 

  </package>

</map>

 

Leaving content frame