title: Hibernate - Foreign key is empty while using mappedBy
body: <p>I've 2 tables <code>Employee</code> &amp; <code>Vehicle</code>, where one employee can have multiple vehicles.
  Below is the mapping that I've defined:</p>
  
  <p><strong>Employee.java</strong></p>
  
  <pre><code>@Entity(name = "emp_details")
  public class Employee {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int empId;
  
      @OneToMany(cascade = CascadeType.ALL, mappedBy="employee")
      private List&lt;Vehicle&gt; vehicles = new ArrayList&lt;&gt;();
  
      public int getEmpId() {
          return empId;
      }
  
      public void setEmpId(int empId) {
          this.empId = empId;
      }
  
      public List&lt;Vehicle&gt; getVehicles() {
          return vehicles;
      }
  
      public void setVehicles(List&lt;Vehicle&gt; vehicles) {
          this.vehicles = vehicles;
      }
  
  }
  </code></pre>
  
  <p><strong>Vehicle.java</strong></p>
  
  <pre><code>@Entity
  public class Vehicle {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int vehicleId;
  
      @ManyToOne
      @JoinColumn(name="empId")
      private Employee employee;
  
      private String name;
  
      public Employee getEmployee() {
          return employee;
      }
  
      public void setEmployee(Employee employee) {
          this.employee = employee;
      }
  
      public int getVehicleId() {
          return vehicleId;
      }
  
      public void setVehicleId(int vehicleId) {
          this.vehicleId = vehicleId;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
  }
  </code></pre>
  
  <p><strong>Main class</strong></p>
  
  <pre><code>public class HibernateTest {
  
      public static void main(String[] args) {
          Employee emp = new Employee();
  
          Vehicle vehicle = new Vehicle();
          vehicle.setName("Honda");
          emp.getVehicles().add(vehicle);
  
  
          SessionFactory sFactory = new Configuration().configure().buildSessionFactory();
          Session session = sFactory.openSession();
          session.beginTransaction();
          session.save(emp);
          session.getTransaction().commit();
          session.close();
  
          StandardServiceRegistryBuilder.destroy(sFactory.getSessionFactoryOptions().getServiceRegistry());
  
      }
  
  }
  </code></pre>
  
  <p>But when I execute this, Vehicle.employee_id is empty. I was expecting that my foreign key will be inserted there.</p>
  
  <p><a href="https://i.stack.imgur.com/l2oOz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l2oOz.jpg" alt="enter image description here"></a></p>
  
  <p>What am I missing?</p>
  
  <p>Thank You</p>