user manual

140 BES Developers Guide
Container-Managed Persistence in Borland Enterprise Server
When you use an EJBObject as a compound type (using the dot notation), you
are actually accessing the underlying get method for the field in the <finder>
definition. For example, the following in the <finder> definition:
order_id = :order.orderId
calls the getOrderId() method on the order EJBObject and uses the result of the
call in the selection criterion.
Specifying relationships between entities
Relational databases (RDBMS) permit records in one table to be associated
with records in another table. The RDBMS accomplishes this using foreign
keys; that is, a record in one table maintains a field (or column) that is a
foreign key or reference to (usually) the primary key of a related record in
another table. You can map these same references among entity beans.
For the CMP engine to map references among entity beans, you use an <ejb-
link> entry in the deployment descriptor. The <ejb-link> maps field names to
their corresponding entities. The CMP engine uses this information in the
deployment descriptor to locate the field's associated entity. (Refer to the pigs
example for an illustration of the <ejb-link> entry.)
Any container-managed persistence field can correspond to a foreign key field
in the corresponding table. When you look at the entity bean code, these
foreign key CMP fields appear as object references.
For example, suppose you have two database tables, an address table and a
country table. The address table contains a reference to the country table. The
SQL create statements for these tables might look as shown below.
create table address (
addr_id number(10),
addr_street1 varchar2(40),
addr_street2 varchar(40),
addr_city varchar(30),
addr_state varchar(20),
addr_zip varchar(10),
addr_co_id number(4) * foreign key *
);
create table country (
co_id number(4),
co_name varchar2(50),
co_exchange number(8, 2),
co_currency varchar2(10)
);
Note that the address table contains the field addr_co_id, which is a foreign key
referencing the country table's primary key field, co_id.
There are two classes that represent the entities which correspond to these
tables, the Address and Country classes. The Address class contains a direct
pointer, country, to the Country entity. This direct pointer reference is an
EJBObject reference; it is not a direct Java reference to the implementation
bean.