O-R Mapping Features - Code snippets
Date: 22-Jul-2002
Entity-deployment
tag - sample code snippet
<entity-deployment name="HotelHome" location="HotelHome" table="Hotels" data-source="jdbc/OracleDS">
location
= JNDI name for the entity bean object
table
= Name of the table in the database into which this entity bean is persisted
If Test table is not present in the database, a new Test table will be created.
Otherwise, the same table will be used.
data-source = JNDI name for the data source
object
Simple
objects and primitive data type mapping - sample code snippet
<cmp-field-mapping name="m_FirstName" persistence-name="FirstName" />
name
= name of the entity bean field
persistence-name = name of the database column into which the entity bean
field is persisted
User
defined serializable object mapping - sample code snippet
<cmp-field-mapping name="m_reservationDetails">
<fields>
<cmp-field-mapping name="m_arrivalDate" persistence-name="ARRIVAL_DATE" />
<cmp-field-mapping name="m_numberOfNights" persistence-name="NO_OF_NIGHTS" />
<cmp-field-mapping name="m_numberOfRooms" persistence-name="NO_OF_ROOMS" />
</fields>
</cmp-field-mapping>
fields
= For grouping fields which are declared in the entity bean. Since
m_reservationDetails is a user-defined serializable object which contains more
than one field, <fields> tag is used to mention that.
Entity
reference mappings - sample code snippet
<cmp-field-mapping name="m_hotel">
<entity-ref home="HotelHome">
<cmp-field-mapping name="m_hotel" persistence-name="HOTEL_ID" />
</entity-ref>
</cmp-field-mapping>
home
= JNDI name of the entity bean to be mapped
Collection
object mapping - sample code snippet
<cmp-field-mapping name="m_facilities">
<list-mapping table="hotel_facilities">
<primkey-mapping>
<cmp-field-mapping name="m_hotelID" persistence-name="HOTEL_ID" />
</primkey-mapping>
<value-mapping type="HotelFacility">
<cmp-field-mapping>
<fields>
<cmp-field-mapping name="m_facilityType" persistence-name="FACILITY_TYPE" />
<cmp-field-mapping name="m_name" persistence-name="FACILITY_TYPE_NAME" />
<cmp-field-mapping name="m_text" persistence-name="FACILITY_TEXT " />
</fields>
</cmp-field-mapping>
</value-mapping>
</list-mapping>
</cmp-field-mapping>
m_facilities = This is
an List object that is to be mapped to a table. This list object holds HotelFacility
user defined serializable object. Attributes of HotelFacility object are persisted
in hotel_facility table.