A direct field mapping is the simplest solution to map an object attribute to fields in database tables. Using this strategy you can assume that every attribute is mapped to exactly one field in a database table. Most classes and their attributes will use this mapping variant.
You may find further information about the attributes of the field element in chapter "Persistence-Metadata".
The following class is going to be made persistent using direct field mappings:
public class Person
{
public Integer key;
protected String lastName;
private String firstName;
}
This class includes three attributes. The attribute key is the primary key of the class. The other attributes correspond directly to columns in a table.
Additionally you have to provide information about which fields in a database table correspond to these attributes. These settings are provided using the mapping-extension with value " direct " for direct field mappings.
Potential nested extensions of this mapping are (with default values if not specified otherwise):
| Extension | Description | Default Value |
|---|---|---|
| table-name | the name of the table (only necessary if there is more than one table for this class) | table-name defined for the class or by naming rule |
| field-name | the name of the database field | extracted from field name using naming rules |
| sql-type | the SQL type (only necessary if the database is not able to provide the correct type) | automatic detection |
We assume, that its not necessary to set the table-name, because its already defined for the class. At minimum the table TPERSON for this class only needs to contain the three fields. Other fields that are not listed in the entries are ignored.
Type conversion between database types and Java types is done automatically by Signsoft intelliBO, that's why no sql-type must be set. Please make sure that type conversion is possible. A String attribute of a class can only be converted into an Integer column in a table under certain conditions. If conversion fails, an exception is raised.
The following example shows how to specify direct field mappings:
<class identity-type="application" name="Person"
objectid-class="com.signsoft.ibo.sample.PersonKey">
<extension key="jdbc" vendor-name="ssibo">
<extension key="table-name" value="TPERSON" vendorname="ssibo"/>
</extension>
...
<field name="key" primary-key="true">
<extension key="jdbc" vendor-name="ssibo">
<extension key="mapping" value="direct" vendor-name="ssibo">
<extension key="field-name" value="FID" vendor-name="ssibo"/>
</extension>
</extension>
</field>
<field name="lastName">
<extension key="jdbc" vendor-name="ssibo">
<extension key="mapping" value="direct" vendor-name="ssibo">
<extension key="field-name" value="FLASTNAME" vendor-name="ssibo"/>
</extension>
</extension>
</field>
<field name="firstName" default-fetch-group="false">
<extension key="jdbc" vendor-name="ssibo">
<extension key="mapping" value="direct" vendor-name="ssibo">
<extension key="field-name" value="FFIRSTNAME" vendor-name="ssibo"/>
</extension>
</extension>
</field>
...
</class>