I have this rather complicated datamodel and i don't know what is common practice for moddeling it in hibernate...
I'll explain the model:
I'm working on an application for my girlfriend who is a teacher. She must be able to enter grades for her students for tests.
This is the datamodel:
Student (id, name)
Class (id,name)
student_classes(id,student_id,class_id) (a student can be part of multiple classes)
test(id,name,class_id)
grade (id,test_id,student_id,grade)
I have made the part were i can get the students from a class with a many to many relation using a set:
Code:
<set cascade="all" fetch="select" lazy="false" name="leerlingen"
optimistic-lock="false" sort="unsorted" table="student_classes">
<key column="class_id"/>
<many-to-many class="Student" order-by="name" column="student_id" unique="false"/>
</set>
Now i want to get a set of grades from a student.
I could create a view and create a model from that view in hibernate. WHen i want to add grades i would also have to model the normal classes for grades and tests instead of using the view.
So normal i would create a query joining student, test and grade.
But... When a student was ill the day he must do the test he will not have an entry in the grade so i would have to use outer joining to also show that test in the list.
WHat should i use for this?
Just create a view in my DB (mysql 5) or use normal tables and model the complete thing in hibernate? If the last... What should i use?
Can i create a single mapping to i can get a set of grader from the students so i will have a getGrades() from the student that gives me the title of the test and the grade for that student?