I am trying to learn one to many Mapping in Hibernate .
The below are my two java classes Shelf.java
public class Shelf {
private Integer id;
private String code;
private Set<Book> books = new HashSet<Book>();
//setter - getter methods
}
Book.java
public class Book {
private String name;
private Integer id;
private Shelf shelf;
//setter - getter methods
}
I have following queries with respect to the above code
- 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 )
2.
<many-to-one name="shelf" class="Shelf" >
<column name="SHELF_ID" not-null="true"></column>
</many-to-one>
Inside hbm Mapping files in Book.hbm.xml file we have
why many-to-one tag here ??