user manual
Chapter 15: Entity Beans and Table Mapping for CMP 2.0 165
Container-Managed Persistence in Borland Enterprise Server
Database cascade delete support
Borland Enterprise Server supports the database cascade delete feature,
which allows an application to take advantage of a database's built in cascade
delete functionality. This reduces the number of SQL operations sent to the
database by the container, therefore improving performance.
To use database cascade delete, the tables corresponding to the entity beans
have to be created with the appropriate table constraints on the respective
database. For example, if you are using cascade delete in EJB 2.0 entity
beans on Order and LineItem entity beans, the tables have to be created as
follows:
create table ORDER_TABLE (ORDER_NUMBER integer, LAST_NAME varchar(20),
FIRST_NAME varchar(20), ADDRESS varchar(48));
create table LINE_ITEM_TABLE (LINE integer, ITEM varchar(100), QUANTITY
numeric, ORDER_NUMBER integer CONSTRAINT fk_order_number REFERENCES
ORDER_TABLE(ORDER_NUMBER) ON DELETE CASCADE);
The <cascade-delete-db> element in the ejb-borland.xml file specifies that a
cascade delete operation will use the cascade delete functionality of the
database. By default this feature is turned off.
Note If you specify the <cascade-delete-db> element in the ejb-borland.xml file, you
must specify <cascade-delete> in ejb-jar.xml.
The XML for <cascade-delete-db> in the ejb-borland.xml is shown in the
following relationship:
<relationships>
<!--
ONE-TO-MANY: Order LineItem
-->
<ejb-relation>
<ejb-relationship-role>
<relationship-role-source>
<ejb-name>OrderEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>lineItems</cmr-field-name>
<table-ref>
<left-table>
<table-name>ORDER_TABLE</table-name>
<column-list>
<column-name>ORDER_NUMBER</column-name>
</column-list>
</left-table>
<right-table>
<table-name>LINE_ITEM_TABLE</table-name>
<column-list>
<column-name>ORDER_NUMBER</column-name>
</column-list>
</right-table>
</table-ref>
</cmr-field>










