Juan,

Assuming a master-detail relationship between two beans, couldn't
all the details (that is, children) be deleted in the ejbRemove()
of the master (that is, the parent)? That is, simply calling the
ejbRemove() on each of the children from within the parent's
ejbRemove().

In EJB 2.0, this is what happens under the covers when you use the
cascade-delete flag; but assuming you wanted to do something similar
programatically (pre EJB 2.0), the above technique should work.

Note that programmatic delete using CMP might run into issues if
the Container defers the database delete(s).

Some (pre) EJB 2.0 containers and persistence managers detect this
automatically and reorder the SQLs; but the point is moot in EJB
2.0 if you set the cascade-delete behavior for relationships.

-krish
Borland

> -----Original Message-----
> From: A mailing list for Enterprise JavaBeans development
> [mailto:[EMAIL PROTECTED]]On Behalf Of Juan Pablo Lorandi
> Sent: Tuesday, July 09, 2002 4:34 PM
> To: [EMAIL PROTECTED]
> Subject: Re: ejb Relation ships
>
>
> Correction; the last post may not work properly:
>
> public class SingleBean implements EntityBean {
>
>         private  javax.ejb.EntityContext  entityContext = null;
> .....
>
>         public void setEntityContext(EntityContext entityContext)
>         throws java.rmi.RemoteException {
>
>                 this.entityContext = entityContext;
>     }
>
> .....
>
>         public void removeMe() {
>                 //cascade-delete
>                 Collection otherBeans =
> otherBeanHome.findBySingle(this.getPrimaryKey() );
>                 for (Iterator it = otherBeans.iterator(); it.hasNext();
> ) {
>                         OtherBean otb = (OtherBean) it.next();
>                         otb.remove();
>                 }
>                 //remove this bean
>                 entityContext.getEJBObject().remove();
>         }
>
> }
>
> Juan Pablo Lorandi
> Chief Software Architect
> Code Foundry Ltd.
> [EMAIL PROTECTED]

> Barberstown, Straffan, Co. Kildare, Ireland.
> Tel: +353-1-6012050  Fax: +353-1-6012051
> Mobile: +353-86-2157900
> www.codefoundry.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