-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Best strategy for exam, question, results model
PostPosted: Mon Nov 12, 2012 10:51 am 
Newbie

Joined: Thu Aug 20, 2009 4:22 am
Posts: 7
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.