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.
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
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>
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>
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. |