title: How does hibernate save one-to-many / many-to-one annotations? (Children not saving)
body: <p>I've inherited a hibernate application and I've run into issues. It seems that the code does not save the child in a One-To-Many relationship. It's bidirectional, but on save of parent object, it doesn't seem to save the child. </p>
  
  <p>The Question class is the parent in this case.</p>
  
  <pre><code>// Question.java
  @Entity
  @SequenceGenerator(name = "question_sequence", sequenceName = "seq_question", allocationSize = 1000)
  @Table(name = "question")
  public class Question {
     protected Long questionId;
     protected Set&lt;AnswerValue&gt; answerValues;
  
     public TurkQuestion(){}
  
     public TurkQuestion(Long questionId){
        this.questionId = questionId;
     }
  
     @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "question_sequence")
     @Column(name = "question_id")
     public Long getQuestionId(){
        return questionId;
     }
  
     @OneToMany(fetch = FetchType.EAGER)
     @JoinColumn(name = "question_id",referencedColumnName="question_id")
     public Set&lt;AnswerValue&gt; getAnswerValues(){
        return answerValues;
     }
  
     public void setQuestionId(Long questionId){
        this.questionId = questionId;
     }
  
     public void setAnswerValues(Set&lt;AnswerValue&gt; answerValues){
        this.answerValues = answerValues;
     }
  }
  </code></pre>
  
  <p>AnswerValue is the child class.</p>
  
  <pre><code>// AnswerValue.java
  @Entity
  @SequenceGenerator(name = "answer_value_sequence", sequenceName = "seq_answer_value", allocationSize = 1)
  @Table(name = "answer_value")
  public class AnswerValue {
      protected Long answerValueId;
      protected Question question;
      protected String answerValue;
  
      public AnswerValue(){}
  
      public AnswerValue(Long answerValueId, Long questionId, String answerValue){
         this.answerValueId = answerValueId;
         this.question = new Question(questionId);
         this.answerValue = answerValue;
      }
  
      @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "answer_value_sequence")
      @Column(name = "answer_value_id")
      public Long getAnswerValueId(){
         return answerValueId;
      }
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "question_id", nullable = false )
      public Question getQuestion(){
         return question;
      }
  
      @Column(name = "answer_value")
      public String getAnswerValue(){
         return answerValue;
      }
  
      public void setAnswerValueId(Long answerValueId){
         this.answerValueId = answerValueId;
      }
  
      public void setQuestion(Question question){
         this.question = question;
      }
  
      public void setAnswerValue(){
         this.answerValue = answerValue;
      }
  }
  </code></pre>
  
  <p>And the DAO:</p>
  
  <pre><code>// QuestionDao.java
  public class QuestionDao {
     public void saveOrUpdateAll(List&lt;Question&gt; list){
        getHibernateTemplate().saveOrUpdateAll(list);
     }
  }
  </code></pre>
  
  <p>It seems when I call saveOrUpdateAll, Question is saved, but the AnswerValue that are children of the Question object are not.</p>
  
  <p>Any suggestions?</p>