Hibernate通过java注释将java中的嵌套集合映射到映射表?
我在使用 java 注释编写 hibernate 映射来解决问题时遇到困难,如下所示。
问题:
表格
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
课程
class Student {
Map<Course,List<Teacher>> courseTeachersMap;
}
要求
- 一门课程可以由多名教师向同一学生组教授。
- 一门课程被分配到一个年级。
- 一个年级可以有多个学生组,为课程分配不同的教师组。
请建议我如何在学生班级中为 courseTeachersMap 属性指定注释。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用
Map
映射ManyToMany
关联,这种映射的典型用例是当您具有三元关联时。例如,如果您有:那么您可以定义以下映射(假设您使用的是 Hibernate Annotations <3.5):
但是我认为您不能有一个“嵌套”
List;
作为Map
内的值,我认为 Hibernate 无法映射它,我会考虑从实体获取List
。参考资料
资源
It is possible to map a
ManyToMany
association 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 theList
from an entity instead.References
Resources