This answer is probably not going to be very satisfying, because you have asked
a implementation which are difficult to answer because everyone does it
differently.  Anyway, here is my take on the CMP and finder methods.

CMP has two advantages:
1. It's for developers because they don't need to write all that SQL code. They
just use a wizard.
2. The container provider can generate optimizations that are proprietary and
hidden.

Reason 2 is especially important with regard to your question.  Some RDBMS have
more efficient but proprietary hooks for executing tasks. ORACLE, for example,
has a proprietary mechanism for making an insert and obtaining the auto
generated primary key.  A container can optimize CMP to take advantage of these
differences without exposing them to the bean code.  Other optimizations might
be done with caching if the EJB server has exclusive use of the database -- I
think Gemstone does this.

As far as ejbFind methods go, I think they have a limited practical application
outside the container environment. In other words, if you are using them to send
a bunch of remote references to a client outside the container its wasteful.
Within the container it may be more productive since you can use lazy mechanisms
to cut down on the overhead. On clients outside the container, large collections
from ejbFind methods produce more overhead than they are worth.

I recommend using listing methods that return arrays or result sets of just the
data you want. You have to hand code these in session or entity beans but the
trade off is worth it at run time.  When you use a listing method you retrieve
only the data you need and you don't bother the client with a lot of unnecessary
remote references.

I examine the listing strategy in-depth on my web site at
http://www.ejbnow.com/ejbtips/ejbtip_4.html

Richard

--
Richard Monson-Haefel
EJB Expert for jGuru.com
( http://www.jguru.com  )

Author of Enterprise JavaBeans
Published by O'Reilly & Associates
( http://www.ejbnow.com )

James Cook wrote:

> I'm sure I'm missing the point. We are trying to demonstrate why BMP cannot
> be optimized as much as CMP. We are also looking hard at the finder method
> for entity beans. To find orders with balances > $100 we would have the
> following BMP query in the Order home...
>
> public Enumeration ejbFindByBalance(BigDecimal amount) throws ...
>
> in this finder we will issue the appropriate SQL to create a bunch of
> Primary Key objects and stuff them into an enumeration.
>
> If the client is the GUI side of an application and wishes to stuff the
> customer names from these orders into a list box, a separate remote call
> would be necessary to obtain the names. This would be required whether using
> CMP or BMP, and you should be whipped with a wet noodle for not using a
> session bean.
>
> So what's the deal with CMP? Can the containers optimise the subsequent
> remote getCustomerName() calls because they instantiated all of those
> objects when they did the original finder query? If so, wouldn't this be an
> incredible waste of time if my client simply wanted to report the number of
> large orders?
>
> I'm not sure if I see the scenario that is causing the grief. Please help.
>
> jim

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to