I have the following two class Answer and SubAnswer:
@Entity
public class Answer {
@OneToMany(mappedBy = "answer", orphanRemoval = true, cascade = {CascadeType.ALL})
List<SubAnswer> subAnswers;
}
public class SubAnswer {
@ManyToOne(optional = false)
Answer answer;
}
and I save them like this
{
Answer ans = new Answer();
List<SubAnswer> subAnswerList = new ArrayList<SubAnswer>();
ans.setSubAnswers(subAnswerList);
ans.add(new SubAnswer());
ans.add(new SubAnswer());
entityManager.save(ans);
}
when I save an Answer, I think it should save the SubAnswers and it saves them but it does not set the SubAnswer.answer field and it remain null