title: Hibernate One to Many and Many to One Relation
body: <p>These two questions answered many of my questions, but I am still struggling to think about in real scenario!</p>
  
  <p>Taking an example from the references.
  Assume I have one Order and Multiple Items associated with it.
  Now assume One Item can have one Returns but one Returns can have multiple Items.</p>
  
  <p>What I understood is, <code>Order to Items will be One to Many Relation</code>.
  Since I need to get Order of an Item, I will create column 'order_fk' in Item table to get it.</p>
  
  <pre><code>//Order entity
  @OneToMany
  @JoinColumn(name = "order_fk")
  private List&lt;Items&gt; items;
  
  //item entity
  @Column(name = "order_fk")
  private Long orderId;
  </code></pre>
  
  <p><code>Return to Items is One to Many mapping. One Return can have multiple Items. But one Item can have only one return id</code></p>
  
  <pre><code>//Return entity
  @OneToMany
  @JoinColumn(name = "return_fk")
  private List&lt;Items&gt; items;
  
  //item entity
  @Column(name = "return_fk")
  private Long returnId;
  </code></pre>
  
  <p>Am I thinking in the right direction? Please make me understand this relations and uni/bi-directional relationships.</p>
  
  <p>Overall, I should get Items for an Order. Get Orderid of given Item. Get Items of Returns and get returnId of given Item.</p>
  
  <p>Reference:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/3113885/difference-between-one-to-many-many-to-one-and-many-to-many">Difference Between One-to-Many, Many-to-One and Many-to-Many?</a>
  <a href="https://stackoverflow.com/questions/16119531/hibernate-jpa-manytoone-vs-onetomany">Hibernate/JPA ManyToOne vs OneToMany</a></li>
  </ol>