title: Connecting to mysql DB using hibernate in java
body: <pre><code>public class Tree&lt;I, A&gt; {
      private final HashMap&lt;I, Node&lt;I, A&gt;&gt; map = new HashMap&lt;&gt;();
      private final Node&lt;I, A&gt; root;
  
      public Tree(I id, A value) {
          root = new Node&lt;&gt;(id, value);
          map.put(id, root);
      }
  
      public void addChild(I parentId, I id, A value) {
          Node&lt;I, A&gt; parent = map.get(parentId);
          Node&lt;I, A&gt; child = new Node&lt;&gt;(id, value);
          parent.children.add(child);
          map.put(id, child);
      }
  
      public A getById(I id) {
          return map.get(id).value;
      }
  
      public String subtreeToString(I id) {
          return map.get(id).toString();
      }
  
      private static class Node&lt;I, A&gt; {
          private final I id;
          private final A value;
          private final ArrayList&lt;Node&lt;I, A&gt;&gt; children = new ArrayList&lt;&gt;();
  
          private Node(I id, A value) {
              this.id = id;
              this.value = value;
          }
  
          private void print(int depth, PrintWriter pw) {
              for (int i = 0; i &lt; depth; i++) {
                  pw.print("\t");
              }
              pw.println("[" + id + ", " + value + "]");
              for (Node&lt;I, A&gt; child : children) {
                  child.print(depth + 1, pw);
              }
          }
  
          @Override
          public String toString() {
              StringWriter writer = new StringWriter();
              print(0, new PrintWriter(writer));
              return writer.toString();
          }
      }
  }
  </code></pre>
  
  <p>sample input</p>
  
  <pre><code>Tree&lt;Integer, String&gt; tree = new Tree&lt;&gt;(1, "Bob");
  tree.addChild(1, 2, "John");
  tree.addChild(1, 3, "James");
  tree.addChild(2, 4, "David");
  tree.addChild(2, 5, "Alice");
  
  System.out.println(tree.subtreeToString(1));
  System.out.println(tree.subtreeToString(2));
  </code></pre>
  
  <p>My problem is, that I want to map the above code to mysql DB using hibernate .I just know basic of hibernate and mysql. How can I achieve this and what steps do i have to follow ?.
  thanks in advance</p>