I have a table, It's structure like bellow:
Code:
id long
value varchar
parentId long
the class is :
Code:
class Node {
long id;
String value;
Node parent;
.....
}
the map file is:
[code] <class name="Node" table="TreeNodes">
<id name="id" type="long" column="id">
<generator class="hilo">
</id>
<property name="value" not-null="true"/>
<many-to-one name="parent" class="Node" column="parentId"/>
<set name="children" lazy="true" >
<key column="parent"/>
<one-to-many class="Node"/>
</set>
</class>code]
I think it's not right, when the node is root will throw null exception, because the root's parent is null, could you tell me some other solutions, thanks very much