I have my beans class like :
Code:
public class Node {
private int id ;
private String name ;
private Node parent ;
private Set<Node>children ;
// Getters and setters will come here
}
My hbm file is :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="testcase.Node" table="DB2ADMIN.NODETest">
<id name="id" type="integer" column="ID" >
<generator class ="assigned"/>
</id>
<property name="name" >
<column name="NAME" />
</property>
<set name="children" inverse="true" cascade="all-delete-orphan">
<key column="CHILDREN_ID" />
<one-to-many class ="testcase.Node"/>
</set>
<many-to-one name="parent" column="CHILDREN_ID" class="testcase.Node" >
</many-to-one>
</class>
</hibernate-mapping>
But using this hbm file i am able to store only those tree in which every node has only one child ... i am not able to save a binary tree or n-ary tree ... can anybody please help me to modify the hbm file so that i can save n-ary tree ?
Thanks.