For each persistence capable class you have to create an XML document – the JDO metadata that declares the persistence properties of the persistence capable class. This document defines the class as persistence capable and declares its persistent and primary key fields. The JDO metadata file must have the extension ".jdo" and must be located in the same directory as the persistence capable class.
You have created the persistence capable classes Employee and Department.
...
1. Open the context menu of your project and choose New → File.
2. Choose <project_name>/source/temp/persistence/gettingstarted/jdo as a location where the file is to be saved.
3. Enter Employee.jdo as the file name.
4. Choose Finish. The file is opened automatically for editing.
5. Enter the following in the file:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE jdo SYSTEM "jdo.dtd"> <jdo> <package name="temp.persistence.gettingstarted.jdo"> <class name="Employee" identity-type="application" objectid-class="Employee$Id"> <field name="empId" persistence-modifier="persistent" primary-key="true"/> <field name="firstName" persistence-modifier="persistent"/> <field name="lastName" persistence-modifier="persistent"/> <field name="salary" persistence-modifier="persistent"/> <field name="department" persistence-modifier="persistent"/> </class> </package> </jdo> |
6. Use the same procedure to create Department.jdo in folder <project_name>/source/temp/persistence/gettingstarted/jdo. Enter the following in the file:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE jdo SYSTEM "jdo.dtd"> <jdo> <package name="temp.persistence.gettingstarted.jdo"> <class name="Department" identity-type="application" objectid-class="Department$Id"> <field name="depId" persistence-modifier="persistent" primary-key="true"/> <field name="name" persistence-modifier="persistent"/> <field name="employees" persistence-modifier="persistent"> <collection element-type="temp.persistence.gettingstarted.jdo.Employee"/> </field> </class> </package> </jdo> |
7. Save and close the files.
Now you have to define the O/R mapping.