I am facing difficulty to write hibernate mapping with java annotation for problem as given below.
Problem:
Tables
Table:Courses_Teachers columns: id course_id teacher_id year(academic year)
Table: Courses_Students columns: id course_id student_id year(academic year)
Table: Courses_Teachers_Students course_teacher_id course_student_id
Classes
class Student {
Map<Course,List<Teacher>> courseTeachersMap;
}
Requirements
- A course can be taught by multiple teachers to same student group .
- A course is assigned to a grade level.
- A grade level can have multiple student groups who are assigned different set of teachers for a course.
Please suggest me how to specify annotation for courseTeachersMap property in class student.
It is possible to map a
ManyToManyassociation using aMap, and a typicall use case for this kind of mapping is when you have a ternary association. For example, if you have:Then you could define the following mapping (assuming you’re using a Hibernate Annotations < 3.5):
But I don’t think you can have a “nested”
List<Teacher>as value inside theMap, I don’t think Hibernate can map that and I’d consider getting theListfrom an entity instead.References
Resources