I have a quiz app in development under my belt, but I'm confused of getting schema design correct need help in this case please. I've quiz, question, answer, and answerOptions Entities as following quiz
@Entity
public class Quiz implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long quizId;
private String quizTitle;
@OneToMany(mappedBy = "quiz", fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
private Set<Question> questions = new HashSet<Question>();
@ManyToMany(mappedBy = "quizs", fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH})
@JsonBackReference
private Set<History> histories = new HashSet<History>();
// omitting getters and setters
}
question
@Entity
public class Question implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long questionId;
private String questionText;
private Integer questionChoices;
private Integer questionNumbers;
@JsonIgnore
@ManyToOne
@JoinColumn(name = "quizId")
private Quiz quiz;
@OneToMany(mappedBy = "question", cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER)
private Set<Option> options = new HashSet<Option>();
@OneToOne(cascade = {CascadeType.REFRESH, CascadeType.PERSIST})
@JoinColumn(name = "answerId")
private Answer answer;
// omitting getters and setters
}
answerOptions
@Entity
@Table(name="answerOptions")
public class Option implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long optionId;
private String optionText;
private static final long serialVersionUID = 1L;
@ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
@JoinColumn(name = "questionId")
private Question question;
// omitting getters and setters
}
, answer
@Entity
public class Answer implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long answerId;
private String answerCorrect;
@OneToOne(mappedBy = "answer", cascade = CascadeType.ALL)
private Question question;
// omitting getters and setters
}
now every thing works good, but where should I save
- Number of Correct Answers.
- Number of Wrong Answers.
- Result of quiz (Pass/Fail)