Yes you can. I guess u are storing both the parent and the child in the same table with the child holding a reference to the parent id. In that case you can use a set in the mapping
Example:
Code:
<class name="Tree" table="Tree">
<id name="id" column="id">
</id>
<property />
.
.
.
<set name="children">
<key column = "parent_id"/>
<one-to-many class="Tree"/>
</set>
</class>
The above mapping says a class tree contains a collection of Tree objects.
So all you have to do to retrieve the entire tree to how many ever levels is a simple hql or a simple load by Id
Your code will be
Code:
session.createQuery("from Tree where id = 1 ").list();
It will return to u an array list of Tree object with id = 1. You can then get each of the tree objects within which you will have a Set of Tree objects that are its children.