Question
I need sort the ExamObjects according to the id
if the ExamObject
is of ExamTask
and sort it according to the questionNumber
if it's ExamQuestion
. How can I do this?
Important
An exam will only have a set of ExamTask
or ExamQuestion
. In other words, one exam cannot have a mixture of ExamTask and ExamQuestion.
Background Information
I have an Entity class called Exam
This class can contain one or more ExamObject
entities.
@Entity
public class Exam {
@OneToMany(mappedBy = "exam" ...)
@OrderBy("id") //I need to order this by question number if its ExamQuestion
private Set<ExamObject> objects;
...
}
ExamObject
can be of two types as below using JOINED
ExamTask
extendsExamObject
ExamQuestion
which extendsExamObject
and has a column calledquestionNumber
ExamObject
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class ExamObject {
@Id
private Long id;
...
ExamTask
@Entity
@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")
public class ExamTask extends ExamObject{
...
ExamQuestion
@Entity
@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")
public class ExamQuestion extends ExamObject{
@Column(name = "question_number")
private Integer questionNumber;
...
Aucun commentaire:
Enregistrer un commentaire