user manual

158 BES Developers Guide
Container-Managed Persistence in Borland Enterprise Server
Basic Mapping of CMP fields to columns
Basic field mapping is accomplished using the <cmp-field> element in the ejb-
borland.xml deployment descriptor. In this element, you specify a field name
and a corresponding column to which it maps. Consider the following XML for
an entity bean called LineItem, which maps two fields, orderNumber and line, to
two columns, ORDER_NUMBER and LINE:
<entity>
<ejb-name>LineItem</ejb-name>
<cmp2-info>
<cmp-field>
<field-name>orderNumber</field-name>
<column-name>ORDER_NUMBER</column-name>
</cmp-field>
<cmp-field>
<field-name>line</field-name>
<column-name>LINE</column-name>
</cmp-field>
</cmp2-info>
</entity>
Mapping one field to multiple columns
Many users may employ coarse-grained entity beans that implement a Java
class to represent more fine-grained data. For example, an entity bean might
use an Address class as a field, but may need to map elements of the class
(like AddressLine1, AddressCity, and so forth) to an underlying database. To do
this, you use the <cmp-field-map> element, which defines a field map between
your fine-grained class and its underlying database representation. Note that
such classes must implement java.io.Serializable and all their data members
must be public.
Consider an entity bean called Customer that uses the class Address to represent
a customer's address. The Address class has fields for AddressLine, AddressCity,
AddressState, and AddressZip. Using the following XML, we can map the class to
its representation in a database with corresponding columns:
<entity>
<ejb-name>Customer</ejb-name>
.
.
<cmp2-info>
<cmp-field>
<field-name>Address</field-name>
<cmp-field-map>
<field-name>Address.AddressLine</field-name>
<column-name>STREET</column-name>
</cmp-field-map>
<cmp-field-map>
<field-name>Address.AddressCity</field-name>
<column-name>CITY</column-name>
</cmp-field-map>