public void testAddChild() {
NodeDAO ndao = new NodeDAO();
Node node = ndao.findByID(5);
Node n1 = new Node("grade 1","grade");
Node n2 = new Node("grade 2","grade");
Node n3 = new Node("grade 3","grade");
node.addChildNode(n1);
node.addChildNode(n2);
node.addChildNode(n3);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
}
mysql> select * from node;
+----+---------+--------+----------------+
| ID | NAME | TYPE | PARENT_NODE_ID |
+----+---------+--------+----------------+
| 5 | myschool| school | NULL |
| 14 | grade 1 | grade | 5 |
| 12 | grade 3 | grade | 5 |
| 13 | grade 2 | grade | 5 |
+----+---------+--------+----------------+
how to controll the order of insert?the result should be :
mysql> select * from node;
+----+---------+--------+----------------+
| ID | NAME | TYPE | PARENT_NODE_ID |
+----+---------+--------+----------------+
| 5 | myscholl| school | NULL |
| 12 | grade 1 | grade | 5 |
| 13 | grade 2 | grade | 5 |
| 14 | grade 3 | grade | 5 |
+----+---------+--------+----------------+
|