!--a11y-->
Defining the O/R Mapping 
For each persistent capable class,
you have to create an XML document that defines how the persistent fields of
the persistent capable class are mapped to the corresponding database tables.
The object/relational (O/R) mapping file must have the extension ".map" and
must be located in the same folder as the persistent capable class. The format
of the class is defined by the
JDO mapping metadata DTD (in the Reference Manual). For
more information about O/R mapping, see Mapping Persistent Classes to Database
Tables.
1. Open the context menu of your project and choose New ® File.
2. Browse to the folder where the Employee class is saved – that is, <project_name>/source/temp/persistence/gettingstarted/jdo.
3. Enter Employee.map as the file name and choose Finish.
4. The file opens automatically. Enter the following contents:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE map SYSTEM "map.dtd"> <map version="1.0"> <package name="temp.persistence.gettingstarted.jdo"> <class name="Employee"> <field name="empId"> <column name="EMPID" table="TMP_EMPLOYEE"/> </field> <field name="firstName"> <column name="FIRST_NAME" table="TMP_EMPLOYEE"/> </field> <field name="lastName"> <column name="LAST_NAME" table="TMP_EMPLOYEE"/> </field> <field name="salary"> <column name="SALARY" table="TMP_EMPLOYEE"/> </field> <relationship-field name="department" multiplicity="one"> <foreign-key name="EMPLOYEE_TO_DEPARTMENT" foreign-key-table="TMP_EMPLOYEE" primary-key-table="TMP_DEPARTMENT"> <column-pair foreign-key-column="DEPID" primary-key-column="DEPID"/> </foreign-key> </relationship-field> </class> </package> </map> |
5. Repeat the procedure described above to create a file named Department.map in folder <project_name>/source/temp/ persistence/gettingstarted/jdo. Enter the following contents:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE map SYSTEM "map.dtd"> <map version="1.0"> <package name="temp.persistence.gettingstarted.jdo"> <class name="Department"> <field name="depId"> <column name="DEPID" table="TMP_DEPARTMENT"/> </field> <field name="name"> <column name="NAME" table="TMP_DEPARTMENT"/> </field> <relationship-field name="employees" multiplicity="many" update="false"> <foreign-key name="EMPLOYEE_TO_DEPARTMENT" foreign-key-table="TMP_EMPLOYEE" primary-key-table="TMP_DEPARTMENT"> <column-pair foreign-key-column="DEPID" primary-key-column="DEPID"/> </foreign-key> </relationship-field> </class> </package> </map> |
You have created the files defining the O/R mapping for the persistence capable classes.
You can now check the overall model for consistency and enhance the classes.
