|
I have three tables like this Table1 Student DepID --pk StudentID --pk StudentName StudentEmail
Table 2 LinkStudentCourses DepID--pk StudentID--pk CourseID--pk
Table3 Courses 1.DepID--pk 2.CourseID--pk 3.CourseName 4.CourseLevel
My requirement is to get all the courses enrolled by student, I mean getting all the corresponding data from courses table based on studentID form student table
So my approach here is using many-to-many relation I have three different classes and xml mappings here is how I linked them through many-to many in Student xml file
<class name="com.syn.model.Student" table="Student" entity-name="student_courses"> <composite-id name="id" class="com.syn.model.StudentId"> <key-property name = "depID" column="DepID" /> <key-property name = "studentID" column="StudentID" /> </composite-id> <property name="studentName" column="StudentName" /> <property name="studentEmail" column="StudentEmail" /> <set name="studentCourses" table="LinkStudentCourses" inverse="true"> <key not-null="true" update="false" > <column name="DepID" /> <column name="StudentID" /> </key> <many-to-many entity-name="courses"> <column name="DepID" /> <column name="CourseID" /> </many-to-many> </set> </class>
Here is the LinkStudentCourses xml mapping
<class name="com.syn.model.LinkStudentCourses" table="LinkStudentCourses" entity-name="link_student_courses"> <composite-id name="id" class="com.syn.model.LinkStudentCoursesId"> <key-property name = "depID" column="DepID" /> <key-property name = "studentID" column="StudentID" /> <key-property name = "courseID" column="CourseID" /> </composite-id> </class>
Here is the Course table hbm
<class name="com.syn.model.Courses" table="Courses" entity-name="courses"> <composite-id name="id" class="com.syn.model.CoursesId"> <key-property name = "depID" column="DepID" /> <key-property name = "courseID" column="CourseID" /> </composite-id> <property name="courseName" column="CourseName" /> <property name="courseLevel" column="CourseLevel" /> </class>
here is the error tomcat throwing when I run this Repeated column in mapping for collection: student_courses.courses column: DepID
How can I solve this problem...
|