TJDO Tutorial: Step 2

Step 1 | Step 2 | Step 3 | Step 4 | Step 5

Step 2: Create a metadata file

Next, we need to define how the class should be persisted. We do this by defining an XML metadata file. This usually includes all fields that will be persisted and any special vendor extensions.

<?xml version="1.0"?>
<!DOCTYPE jdo PUBLIC "-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 1.0//EN" "">

  <package name="test">
    <class name="Person">
      <field name="firstName">
        <extension vendor-name="triactive" key="length" value="max 32"/>
      <field name="lastName">
        <extension vendor-name="triactive" key="length" value="max 32"/>
      <field name="age"/>

Note that the firstName and lastName fields both use the "triactive" vendor extension "length". This is required for any persistent String field so an appropriate database column can be created (i.e. CHAR, VARCHAR, etc.). The possible TJDO vendor extensions are listed in the metadata DTD documentation.