Entering content frame

Function documentation Mapping to Separate Tables Locate the document in its SAP Library structure

Use

In this scenario, all fields declared in a subclass are mapped to the columns of a table that contains only these columns and the primary columns, which are equal to the primary key columns of the superclass.

Example

There is an inheritance hierarchy with three classes. Class example.jdo.Manager and class example.jdo.Subordinate both inherit from class example.jdo.Employee. The root class example.jdo.Employee contains a key field empid. All classes have a private field name. The declared fields of each class are mapped to a separate table: class example.jdo.Employee is mapped to TMP_EMPLOYEE, class example.jdo.Manager is mapped to TMP_MANAGER and class example.jdo.Subordinate is mapped to TMP_SUBORDINATE. The key field empid is mapped to the column EMPID in all tables. For an instance of class example.jdo.Subordinate, table rows can be found in tables TMP_EMPLOYEE and TMP_SUBORDINATE, but not in TMP_MANAGER. In table TMP_EMPLOYEE, there is a discriminator column DISC that contains the type of a table row. For all instances of the classes that belong to this inheritance hierarchy, a table row exists in table TMP_EMPLOYEE. The subclasses contain additional mapping information for the key field empid, describing the primary key columns of the tables to which the subclasses are mapped.

 

This graphic is explained in the accompanying text

 

The XML metadata has the following contents:

 

<jdo>

  <package name="example.jdo">

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

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

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

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

    </class>

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

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

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

    </class>

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

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

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

    </class>

  </package>

</jdo>

 

<map version="1.0">

  <package name="example.jdo">

    <class name="Employee">

      <discriminator>

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

      </discriminator>

      <field name="empid">

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

      </field>

      <field name="name">

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

      </field>

    </class>

    <class name="Manager">

      <field name="empid" virtual="true">

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

      </field>

      <field name="name">

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

      </field>

    </class>

    <class name="Subordinate">

      <field name="empid" virtual="true">

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

      </field>

      <field name="name">

        <column name="NAME" table="TMP_SUBORDINATE"/>

      </field>

    </class>

  </package>

</map>

 

See also:

 

Mapping to One Table

 

Leaving content frame