findBy methods on the home interface should return either the remote interface
or a Collection of remote interfaces. So just make findByParent return a
collection of categories. So your code would look something like...

InitialContext context = new InitialContext();
Object obj = context.lookup("java:comp/env/ejb/Category");
CategoryHome ch = (CategoryHome)PortableRemoteObject.narrow(obj, CategoryHome.class);

Collection col = ch.findByParent("Furniture");
Iterator i = col.iterator();
while (i.hasNext())
{
   Category cat = (Category)i.next();
   ... do stuff ...
}



-t

On Tue, Sep 05, 2000 at 02:04:37PM -0400, Rhodes, Phillip C. wrote:
> I have a Entity bean called "CategoryBean" that is recursive.  Categories
> can have children categories, and those categories can have children, etc.
> Example:
>
> Furniture
>         Chair
>         Couch
> Bedding
>         Sheets
>         Blankets
>
> My ejb "CategoryBean" needs to get its children.  For example, user clicks
> on category, need to show sub-categories.  I created a method called
> getChildCategories() in my CategoryBean object.  The method
> getChildCategories()  does the lookup on the home object and calls the
> findByParent(String categoryId)  finder on the home object.
>
> My question is, is this indirection necessary?  Why would I need my instance
> of an EJB to look up another (possible its own) reference to lookup its
> children?
>
> Does anyone have example of parent/child relationship as entity bean?
>
> Thanks!
>
>
> public Enumeration getChildCategories() throws RemoteException {
>         CategoryHome home = null;
>         try {
>                 Context initCtx = new InitialContext(ctx.getEnvironment());
>
>                 home = (CategoryHome) initCtx.findByParent(categoryId);
>
>         }  catch (Exception e) {
>                 throw new ServerException("Lookup failed",e);
>         }
> }
>
>
> Phillip Rhodes
> [EMAIL PROTECTED]
> Alcoa eCommerce
> https://www.ALCOADIRECT.COM
> 826B Two Allegheny Center Pittsburgh, PA  15212
> (412) 553-4900  (phone)  (412) 553-2484 (fax)
>
> ===========================================================================
> 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".
>

--

   Tony Abbott                          [EMAIL PROTECTED]

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