Hi,
I've got a model where exam has a many to many mapping to questions, and each question has many results.
At the moment I have an Exam class and Question class with a join table called exam_question. I also have a result class which has exam_id, question_id and result. I think I am mapping the exam result entity incorrectly as it returns all results for the question, not the result for the exam-question
Code:
public class Exam
@Id
private int examId;
@ManyToMany
@JoinTable(name="exams_questions", joinColumns={
@JoinColumn(name="exam_id")},
inverseJoinColumns={@JoinColumn(name="question_id")})
private List<Question> questions;
public class Question
@Id
private int questionId
//bi-directional many-to-one association to QuestionResult
@OneToMany(mappedBy="question")
private List<QuestionResult> questionResults;
public class QuestionResult
@Id
private int questionResultId
private int examId;
private int questionId;
//bi-directional many-to-one association to Question
@ManyToOne
@JoinColumn(name="question_id", nullable=false, insertable=false, updatable=false)
private Question question;
My problem is drawning out the results for a particular exam. Say I want my object to be constructed in this manner:
Exam - Questions - Question Results (only for the questions related to the exam)
Chances are I have structured my model wrongly, but can any provide a pointer as to what kind of model I should be looking at to achieve what I want?
I've looked at join tables with extra columns and ternary assocaitions but I don't think they provide me with what I need. The join tables with extra columns will not allow for me to store multiple results for the same exam/question. Ternary - am not quite sure how this works, maybe am not understanding the concept behind it.
Thanks in advance