title: Hibernate : one to many mapping in Hibernate
body: <p>I am trying to learn one to many Mapping in Hibernate .</p>
  
  <p>The below are my two java classes 
      Shelf.java </p>
  
  <pre><code>    public class Shelf {
      private Integer id;
      private String code;
      private Set&lt;Book&gt; books = new HashSet&lt;Book&gt;();
  
  //setter - getter methods
  
  }
  
  
  Book.java
  
      public class Book {
      private String name;
      private Integer id;
      private Shelf shelf;
  
  //setter - getter methods
  }
  </code></pre>
  
  <p>I have following queries with respect to the above code </p>
  
  <ol>
  <li>Should be treat Shelf as the Master Table and Book as the Child Table ?? (Because Shelf.java  contains many Objects of Object Book ?? or there isn't any such thumb rule to decide which is Master and Child Table ) </li>
  </ol>
  
  <p>2.</p>
  
  <pre><code> &lt;many-to-one name="shelf" class="Shelf" &gt;
              &lt;column name="SHELF_ID" not-null="true"&gt;&lt;/column&gt;
          &lt;/many-to-one&gt;
  </code></pre>
  
  <p>Inside hbm  Mapping files in Book.hbm.xml file we have</p>
  
  <p>why many-to-one tag here ??</p>