user manual
Chapter 14: Entity Beans and CMP 1.1 in Borland Enterprise Server 139
Container-Managed Persistence in Borland Enterprise Server
The Container composes a SQL select statement whose where clause is:
balance > ?
Note that the :balance parameter in the deployment descriptor becomes a
question mark (?) in the equivalent SQL statement. When invoked, the
Container substitutes the value of the parameter :balance for the ? in the where
clause.
Compound parameters
The Container also supports compound parameters; that is, the name of a
table followed by a column within the table. For this, it uses the standard dot
(.) syntax, where the table name is separated from the column name by a dot.
These parameters are also preceded by a colon.
For example, the following finder method has the compound parameters
:address.city and :address.state:
<finder>
<method-signature>findByCity(Address address)</method-signature>
<where-clause>city = :address.city AND state = :address.state</where-
clause>
</finder>
The where clause uses the city and state fields of the address compound object
to select particular records. The underlying Address object could have Java
Beans-style getter methods that correspond to the attributes city and state.
Or, alternatively, it could have public fields that correspond to the attributes.
Entity beans as parameters
An entity bean can also serve as a parameter in a finder method. You can use
an entity bean as a compound type. To do so, you must tell the CMP engine
which field to use from the entity bean's passed reference to the SQL query. If
you do not use the entity bean as a compound type, then the Container
substitutes the bean's primary key in the where clause.
For example, suppose you have a set of OrderItems entity beans associated
with an Order entity object. You might have the following finder method:
java.util.Collection OrderItemHome.findByOrder(Order order);
This method returns all OrderItems associated with a particular Order. The
deployment descriptor entry for its where clause would be:
<finder>
<method-signature>findByOrder(Order order)</method-signature>
<where-clause>order_id = :order[ejb/orders]</where-clause>
</finder>
To produce this where clause, the Container substitutes the primary key of the
Order object for the string :order[ejb/orders]. The string between the brackets
(in this example, ejb/orders) must be the <ejb-ref> corresponding to the home
of the parameter type. In this example, ejb/orders corresponds to an <ejb-ref>
pointing to OrderHome.










