Hello,

Try assign to each NewsItemEJB an id and add a finder method in your ejb
home interface. Somethink like:

        public class NewsItemEJB {
                public int newsItemId; // unique
                public int newsItemParentId; // unique
                public String text;
                public NewsItem getParent() {
                        // Perform lookup after newsItemParentId and return the object
                        // gethome -> findByParent
                }
        }

        public class NewsItemHome ... {
                NewsItem findByParent(int parentId) throws ... ;
                Collection findByChilds(int parentId) throws ...; //Return all childs
        }

I hope this will help you.

Regards
Petrica GHIURCA

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Heiko
Gottschling
Sent: Friday, January 19, 2001 6:52 PM
To: Orion-Interest
Subject: Question recursive data structure - how on earth does this
work?


Hi,

the Orion distribution contains a small example application (news). A news
item is modeled by an CMP entity bean with remote interface NewsItem and EJB
class NewsItemEJB. News items can be ordered hierarchically, i.e. a news
item
can have a parent. The code looks like this:

  public class NewsItemEJB {
    public NewsItem parent;
    public String text;

    public NewsItem getParent() {
      return parent;
    }
    [...]

As you see, it has a CMP field 'parent' of type NewsItem (which is the
remote
interface of the bean itself)...

How does this work?

Since there is a method 'getParent()', it seems like the container, after
retrieving a news item from the database, goes on and fetches also the
parent
record, placing a reference to its remote interface in the sub-record...
this
may even continue if the hierarchy is deeper

Any insights?

thx
Heiko



Reply via email to