title: Null values are inserted in the foreign key fields with Hibernate
body: <p>I have a <code>Question</code> Entity and <code>Tag</code> entity with getter, setter methods and a <code>OneToMany</code> relationship from <code>question</code> to <code>tag</code> and a <code>OneToOne</code> relationship from <code>question</code> to <code>user</code></p>
  
  <pre><code>public class Question {
  
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      private Long id;
  
      @Column(name="title")
      private String title;
  
      @Column(name="body")
      private String body;
  
      @Temporal(TemporalType.DATE)
      @Column(name="date_created")
      private Date date_created;
  
      @OneToOne(cascade=CascadeType.ALL)
      @JoinColumn(name="user_id")
      private User user;
  
      @OneToMany(cascade=CascadeType.ALL)
      @JoinColumn(name="tag_id")
      private Tag tag;
  
      @Column(name="answer_count")
      private int answer_count;
  
      @Column(name="view_count")
      private int view_count;
  
      public Question() {
  
  }
  </code></pre>
  
  <p>Tag entity</p>
  
  <pre><code>public class Tag {
  
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      private Long id;
  
      @Column(name="name")
      private String name;
  
      @Column(name="username")
      private String username;
  
      @Temporal(TemporalType.DATE)
      @Column(name="date_created")
      private Date date_created;
  
      public Tag() {
  
  }
  </code></pre>
  
  <p>When I try to insert a question using Postman with the following details:</p>
  
  <pre><code>{
      "title": "stefanyyyxx",
      "body": "stefandoyee44",
      "date_created": "2019-02-27",
      "user_id" : 1,
      "tag_id": 1,
      "answer_count": 0,
      "view_count": 0
  }
  </code></pre>
  
  <p>QuestionRepository.java:</p>
  
  <pre><code>@Override
  public void save(Question theQuestion) {
  
      // get the current hibernate session
      Session currentSession = entityManager.unwrap(Session.class);
  
      // save employee
      currentSession.saveOrUpdate(theQuestion);
  }
  </code></pre>
  
  <p>Null values are being inserted for <code>user_id</code> and <code>tag_id</code> though I used <code>JoinColumn()</code>. </p>
  
  <p>MySQL:</p>
  
  <p><a href="https://i.stack.imgur.com/pzqoD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pzqoD.png" alt="enter image description here"></a></p>