JSP/Struts2/Hibernate: loop through a self-referencing table.

Posted by TBW on Stack Overflow See other posts from Stack Overflow or by TBW
Published on 2011-01-07T13:12:48Z Indexed on 2011/01/08 2:53 UTC
Read the original article Hit count: 217

Hello everyone,

Let's say we have a self-referencing table called PERSON, with the following columns: ID, PARENT, where PARENT is a foreign key to the ID column of another element in the PERSON table. Of course, many persons can have the same parent.

I use Hibernate 3 in lazy fetching mode to deal with the database. Hibernate fetches a person element from the database, which is then put in the ValueStack by the Struts2 action, to be used on the result JSP page.

Now the question is : In JSP, how can I do to display all the child (and the child's child, and so on, like a family tree) of this person element?

Of course, for the n+1 children I can use the < s:iterator> tag over the person.person. I can also nest another < s:iterator> tag over person.person.person to get the n+2 children.

But what if I want to do this in an automated manner, up to the last n+p child, displaying in the process all the children of all the n+1..n+p elements?

I hope I have been clear enough. Thank you all for your time.

-- TBW.

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about jsp