web server - Borland Technical Publications

web server - Borland Technical Publications web server - Borland Technical Publications

techpubs.borland.com
from techpubs.borland.com More from this publisher
12.11.2014 Views

Container-Managed Persistence in Borland Enterprise Server CASE 2: a bidirectional one-to-many relationship. SPECIAL_INFO CUSTOMER_NO Next, we finish the entry by providing its other half, the SpecialInfo bean. Since this is a mono-directional relationship, we don't need to specify any table elements. We only need add the following, defining the other half of the relationship and its source: SpecialInfo Here, we have a Customer entity bean with a primary key, CUSTOMER_NO, that is also a foreign key in an Order entity bean. We want the Borland EJB Container to manage this relationship. The Customer bean uses a field called “orders” that links a customer to his orders. The Order bean uses a field called “customers” for linking in the reverse direction. First, we define the relationship and its source for the first direction: setting up the mapping for a Customer's orders. Customer orders Then, we add the table references to specify the relationship between the tables. We're basing this relationship on the CUSTOMER_NO column, which is a primary key for Customer and a foreign key for Orders: CUSTOMER CUSTOMER_NO ORDER CUSTOMER_NO Chapter 15: Entity Beans and Table Mapping for CMP 2.0 137

Container-Managed Persistence in Borland Enterprise Server CASE 3: a many-tomany relationship. We're not quite done with our relationship, though. Now, we need to complete it by specifying the relationship role for the other direction: Customer customers ORDER CUSTOMER_NO CUSTOMER CUSTOMER_NO . . If you define a many-to-many relationship, you must also have the CMP engine create a cross-table which models a relationship between the left table and the right table. Do this using the element, whose XML is: You may name this cross-table whatever you like using the element. The two elements correspond to columns in the left and right tables whose relationship you wish to model. For example, consider two tables, EMPLOYEE and PROJECT, which have a many-to-many relationship. An employee can be a part of multiple projects, and projects have multiple employees. The EMPLOYEE table has three elements, an employee number (EMP_NO), a last name (LAST_NAME), and a project ID number (PROJ_ID). The PROJECT table contains columns for the project ID number (PROJ_ID), the project name (PROJ_NAME), and assigned employees by number (EMP_NO). 138 BES Developer’s Guide

Container-Managed Persistence in <strong>Borland</strong> Enterprise Server<br />

CASE 2: a bidirectional<br />

one-to-many<br />

relationship.<br />

<br />

SPECIAL_INFO<br />

CUSTOMER_NO<br />

<br />

<br />

<br />

<br />

Next, we finish the entry by providing its other half, the SpecialInfo<br />

bean. Since this is a mono-directional relationship, we don't need to specify any table<br />

elements. We only need add the following, defining the other half of the relationship<br />

and its source:<br />

<br />

<br />

SpecialInfo<br />

<br />

<br />

<br />

<br />

Here, we have a Customer entity bean with a primary key, CUSTOMER_NO, that is also a<br />

foreign key in an Order entity bean. We want the <strong>Borland</strong> EJB Container to manage this<br />

relationship. The Customer bean uses a field called “orders” that links a customer to his<br />

orders. The Order bean uses a field called “customers” for linking in the reverse<br />

direction. First, we define the relationship and its source for the first direction: setting up<br />

the mapping for a Customer's orders.<br />

<br />

<br />

<br />

<br />

Customer<br />

<br />

<br />

orders<br />

Then, we add the table references to specify the relationship between the tables. We're<br />

basing this relationship on the CUSTOMER_NO column, which is a primary key for Customer<br />

and a foreign key for Orders:<br />

<br />

<br />

CUSTOMER<br />

<br />

CUSTOMER_NO<br />

<br />

<br />

<br />

ORDER<br />

<br />

CUSTOMER_NO<br />

<br />

<br />

<br />

<br />

<br />

Chapter 15: Entity Beans and Table Mapping for CMP 2.0 137

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!