Mapping Classes to Tables
If your object model does not use inheritance, you usually have a
separate relational table for each class. We cover the mapping of
classes in an inheritance hierarchy later in this chapter. To establish
a mapping from a Java class to a specific table, in most JDO
implementations you specify the mapping in your JDO metadata with an
extension
element nested within the
class
element. For example, the following example illustrates
the metadata necessary to map the MediaItem
class
to a table called Items
:
<class name="MediaItem" > <field name="rentalItems"> <collection element-type="RentalItem"/> </field> <extension vendor-name="vendorX" key="table" value="Items" /> <extension vendor-name="vendorY" key="sqlname" value="Items" /> </class>
You identify the implementation you are using in the vendor-name
attribute. As we mentioned
previously, the datastore mappings in JDO 1.0.1 are
implementation-specific. This may be standardized in JDO 2.0. Each JDO
vendor provides documentation explaining which value to use for the
vendor-name
attribute and which
values are supported for the key
attribute.
In the previous code, we provided the metadata for two vendors,
identified as vendorX
and vendorY
. An implementation will use only
metadata extensions that it recognizes. This allows you to place the
metadata for multiple vendors in the same JDO metadata file. vendorX
uses a value of "table
" for the key
attribute to indicate which relational
table the MediaItem
class should ...
Get Java Data Objects now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.