In my java code, I created a tree, where a node in the tree is of type Node. The node has a name, attribute and children of type Node. I am using db4o in order to store the tree. I am doing that by simply storing the root node of the tree. However, I found out that db4o does not store all the children nodes of an object node. When I retrieve the root from the database, and traverse the tree, I can only traverse up to 3 levels of the tree. It seems that the children nodes at lower levels are lost. Can someone help me so I don't lose any node? Thank you.
Below is my code:
Node node1= new Node("root","this is the root",new ArrayList<Node>());
Node node2= new Node("zaid","123",new ArrayList<Node>());
Node node3= new Node("saad","999",new ArrayList<Node>());
Node node4= new Node("safia","555",new ArrayList<Node>());
Node node5= new Node("ahmad","000",new ArrayList<Node>());
node1.getChildren().add(node2);
node2.getChildren().add(node3);
node3.getChildren().add(node4);
node4.getChildren().add(node5);
ObjectContainer db= Db4oEmbedded.openFile(Db4oEmbedded.newConfiguration(),"db");
db.store(node1);
Node node= new Node("root",null,null);
List<Node> result= db.queryByExample(node);
node= result.get(0);
System.out.println(node.getName()
+","+node.getChildren().get(0).getName()
+","+node.getChildren().get(0).getChildren().get(0).getName()
+","+node.getChildren().get(0).getChildren().get(0).getChildren().get(0).getName());
I am getting an exception at the last line of code saying the following:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0