I have the following entities within my Micronaut 3.0.3 application.
public class Game extends BaseEntity {
...
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@ToString.Exclude
@OrderColumn(name = "sort_index")
private List<Question> questions = new ArrayList<>();
...
}
public abstract class Question extends BaseEntity {
... // omitted
}
The order column works well when I'm accessing the questions through the level, so that hibernate can handle the ordering for me:
// (pseudo) ordered correctly:
gameRepository.findById(id).getQuestions();
But I want to use the question repository directly, like this:
@Query(
"""
select q from Question q, Game g
where g.id = :game
and q in elements(g.questions)
----> order by sort_index of game_questions table
""")
Collection<Question> findAllByGame(UUID game);
Need help with the ordering part of the questions.