title: Hibernate save object (one to many relationship) foreign key is null
body: <p>I have one to many relationships between person class and car class. A person can own many cars and vice versa. I am using restful API to post data. My annotations and Get service is working fine but my post service throws " <code>java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL" error</code> whenever I try to insert new data. Child table <code>foreign key</code> is being inserted as <code>null</code>.  </p>
  
  <p>Here is part of my code. </p>
  
  <p>Person.java</p>
  
  <pre><code> private List&lt;Car&gt; cars = new ArrayList&lt;Car&gt;();
  
  @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="person")    
  @JsonManagedReference
  public List&lt;Car&gt; getCars() {
    return cars;
   }
  </code></pre>
  
  <p>Car.java</p>
  
  <pre><code>private Person person;  
  
      @ManyToOne
      @JoinColumn(name = "PERSON_ID", nullable = false, updatable = true, insertable = true)
      @JsonBackReference
      public Person getPerson() {
          return person;
      }
  </code></pre>
  
  <p>My service class: </p>
  
  <pre><code>@POST
          @Path("/PersonRegistration")
          @Consumes(MediaType.APPLICATION_JSON)
          public Response postPersonCars(Person person) throws Exception{
  
              Session session = null;     
              ObjectMapper mapper = new ObjectMapper();   
              //Person per = new Person();
              //Car cars = new Car();
              try{
                  session = HibernateUtil.getSessionFactory().openSession();
                  session.beginTransaction(); 
                  //per.setCars(person.getCars());
                  session.save(person);
                  session.getTransaction().commit();
  
              }catch(Exception e){
                  e.printStackTrace();
                  throw e;
              }finally{
                  if(null != session){
                      session.close();
                  }
              }
  
              return Response.status(201).entity(mapper.writeValueAsString(person)).build();
          }
  </code></pre>