We do what you suggest, and it works. It is slow, however. An alternative is to invoke findAll() and link the nodes using some hash table.
- Avi -- This signature intentionally left blank. > -----Original Message----- > From: Rahul Desai [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, October 17, 2001 06:54 > To: [EMAIL PROTECTED] > Subject: problem querying trees > > > Hi all, > > My problem is as follows: > > I have a table as follows > > ID Name ParentId > ------------------------- > 1 a NULL > 2 b 1 > 3 c 1 > 4 d 2 > 5 e 2 > 6 f 3 > > > Basically it represents a tree.I am planning to have CMP bean for this > table.On the Client(Browser), I need to show the entire > tree(Just like a > JTree).I am not able to figure out the best way to do this. > The first thing that strikes me is to have a session bean > queries for the > ROOT node(findByParentId(null)) first and the recursivley > queries for the > child nodes (findByParentId(parentId)) and then builds some Tree > DataStructure out of these and pass it back to the servlet. I > dont know if > this approach is correct because this involves lot of trips > to the database. > > If anybody has better solutions for this, please let me know > > Thanks in advance, > Rahul Desai > > ============================================================== > ============= > 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". > =========================================================================== 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".
