title: How to read OneToMany or ManyToOne relationship between entities in Hibernate?
body: <p>I am learning hibernate and trying to understand how to establish the relationship between two entities (<code>OneToOne</code>, <code>OneToMany</code>, <code>ManyToMany</code>). Consider the simple scenario:</p>
  
  <h1>User Entity:</h1>
  
  <pre><code>@Entity
  class User {
      @Id
      private userId;
  
      private Vehicle vehicle;
  
      // other code
  }
  </code></pre>
  
  <h1>Vehicle Entity:</h1>
  
  <pre><code>@Entity
  public class Vehicle {
      @Id
      private int vehicleId;
      private String desc;
  
      // other code
  }
  </code></pre>
  
  <h1>My aim is to specify:</h1>
  
  <p><code>One to Many relationship</code> or  <code>One to one</code> relationship between <code>User</code> and <code>Vehicle</code> entities.</p>
  
  <p>I know there are <code>OneToOne</code> , <code>OneToMany</code> annotations, but I not able to understand how is this relationship interpreted? Does it depend in which Entity the other Entity is placed?</p>
  
  <h1>For example:</h1>
  
  <pre><code> @Entity
  class User {
      @Id
      private userId;
  
      private Vehicle vehicle;
  
      // other code
  }
  </code></pre>
  
  <p>As we can see, I have placed the <code>Vehicle</code> entity inside the <code>User</code> entity and if I use <code>OneToMany</code> annotation on top of <code>Vehicle</code> entity, does it mean 1:M relationship between <code>User</code> -> <code>Vehicle</code> entity.</p>
  
  <p>Can anyone help me understand this?</p>