Michael Boyle wrote:

> Suppose we have a coarse-grained Order entity bean which manages
> multiple non-bean Items, based on an RDB with Order and Item tables.
>
> If we're using bean-managed persistence, then in Order's ejbStore()
> method, I have to save all the Items to the DB.  But since the
> most recent operation on my Order bean may have changed the list
> of the Order's items arbitrarily (added some, deleted some), what
> I really have to do is:
>     - delete all Items in the DB corresponding to the Order
>     - insert all the new Items
>
> This seems a bit inefficient if just a single Item has been
> added or deleted!
>
> Am I missing something?

I would design it differently.  Instead of treating the list as one persistent
field, treat each item in the list as persistent data. Only load the items as
you need them and change them individually.  A good O/R CMP EJB vendor can do
this or you can do it with intelligent design of BMP entities.  Either way, the
necessity to load all the dependent data at once is a myth.  Dependent data can
be loaded as needed and changed one element at a time if desired.  If, for
example in BMP, you need to access all the order items for an order obtain them
in the assessor method when its invoked, wrap the data in java objects, and
return the list as a vector to the client.  If the client needs to change
change one of the order items, provide a method allows one item to be replaced
with another one.

public interface Order extends EJBObject {
   public Vector items( ) throws RemoteException;
   public void addItem(OrderItem item) throws RemoteException;
   public void removeItem(OrderItem item) throws RemoteException;
   public void update(OrderItem originalItem, OrderItem updateItem)
     throw RemoteException;
}

public class OrderItem implements Serializable {
       int productID;
       Date date;
       int count;
       double unitPrice;
}

There is more about the use of dependent objects on my web site
(www.ejbnow.com/ejbtips.html)
--
Richard Monson-Haefel
Author of Enterprise JavaBeans
Published by O'Reilly & Associates
( http://www.monson-haefel.com )

===========================================================================
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