|
I have an entity Quizz containing the following association:
@OneToMany(mappedBy = "quizz", cascade = CascadeType.ALL, orphanRemoval = true) @OrderColumn(name = "position") private List<Question> questions = new ArrayList<>();
and the following method to add a question at a given position in the list:
public void addQuestion(int index, Question question) { question.setQuizz(this); questions.add(index, question); }
But calling this method actually adds the question at the end of the list in database (i.e. its position is set to the last position, and the other questions positions are not updated)
Workaround that I discovered by debugging:
public void addQuestion(int index, Question question) { question.setQuizz(this); questions.add(index, question); Hibernate.initialize(questions); }
Test case attached.
|