JPOX
JPOX
 JPOX Version 1.0
Configuration | Tutorials | Worked Examples | Developer
Obtaining JPOX
JPOX Preparation
JPOX Runtime
JDO Mode : Existing Schema

This is chosen when you have to support a legacy database schema and want to continue from the point you are at, and with the data you already have. Your tables have their own primary keys already defined and so you must retain those.

datastore identity

This mode is chosen when you don't want to control the ids of your tables in your existing schema (other than that they fit in with what is already inserted in the schema). To operate in this mode, you need to follow some rules

  • Your table must have one and only one primary key column that can be mapped to a java.lang.Long. In general, the database data types compatible are: INT, INTEGER, SMALLINT and other numeric data types.
  • You must set the primary key column name (extension: key-column-name) at the class level in the MetaData.
  • Set the MetaData for your class to be datastore-identity
  • Set the MetaData column names and table name and types to match exactly your existing table.

So to give an example, if you have a table with name "PEOPLE", with columns "CODE", "FIRSTNAME", "LASTNAME", (with CODE being the primary key column of type INT), and a class as follows

public class Person
{
    protected String forename;
    protected String surname;
}
                

you would define the Meta-Data for this as follows

    <class name="Person" identity-type="datastore"> 
        <extension vendor-name="jpox" key="table-name" value="PEOPLE"/>
        <extension vendor-name="jpox" key="key-column-name" value="CODE"/>
        <field name="forename">
            <extension vendor-name="jpox" key="column-name" value="FIRSTNAME"/>
            <extension vendor-name="jpox" key="length" value="max 80"/>
        </field>
        <field name="surname">
            <extension vendor-name="jpox" key="column-name" value="LASTNAME"/>
            <extension vendor-name="jpox" key="length" value="max 100"/>
        </field>
    </class>
                
application identity

This mode is chosen when you want to control the ids of your tables in your existing schema (as well as to fit in with the data that is already there). To give an example, if you have a table with name "PEOPLE", with columns "CODE", "FIRSTNAME", "LASTNAME", with code as the primary key column and a class as follows

public class Person
{
    protected int id;
    protected String forename;
    protected String surname;
}
public class PersonKey implements Serializable
{
    public int id;
    public PersonKey(String str) {...}
    public PersonKey() {...}
    public String toString() {...};
    public boolean equals(Object obj) {...}
    public int hashCode() {...}
}
                

you would define the Meta-Data for this as follows

    <class name="Person" identity-type="application" 
                    objectid-class="org.jpox.samples.PersonKey">
        <extension vendor-name="jpox" key="table-name" value="PEOPLE"/>
        <field name="id" primary-key="true">
            <extension vendor-name="jpox" key="column-name" value="CODE"/>
        </field>
        <field name="forename">
            <extension vendor-name="jpox" key="column-name" value="FIRSTNAME"/>
            <extension vendor-name="jpox" key="length" value="max 80"/>
        </field>
        <field name="surname">
            <extension vendor-name="jpox" key="column-name" value="LASTNAME"/>
            <extension vendor-name="jpox" key="length" value="max 100"/>
        </field>
    </class>
                
Additions

In addition to the above general rules, if you have any columns in your existing table that are of non-standard types or length, you may need to make use of the length, precision, and scale extension tags. Please refer to the Meta-Data Reference for details of these tags.