|
Hi ,
I have to make a simple test application using Hibernate .
Problem statement is like this -
-----------------------------------------------------------------------
A student can enroll for many courses and
for each course a student is enrolled he can have marks .
WE have to provide add, delete display functionality for this requirement .
-----------------------------------------------------------------------
The Database tables that i have made are as follows
1) Table:Student (id , Name , Address )
2) Table:Course (id , name )
3) Association Table: Student_course(id , studentid , courseid , marks)
the studentid and courseid are foreign keys referencing student and course tables PK respectively .
I have made POJO's for Student and Course Tables .
Besides other properties In the Student POJO i have also added a
member "courses" of type Set I have done the many-to-many for it
in the Student.hbm.xml file like this
.......................................
...
<set name="courses" table="STUDENT_COURSE" order-by="COURSEID">
<key column="STUDENTROLLNO"/>
<many-to-many column="COURSEID" class="sis.Course" />
</set>
...
........................................
Now the problem is that i am unable to figure out how to model the
"Marks" .
Marks information is in the association table student_course ,
I can neither put this info in Student Class nor in Course Class .
Once the student object is loaded i can get the courses associated with him , but how can i get the marks associated with thoses courses .
Similary when i update the student object student_course is also updated
but with my current mapping "marks" column is not updated , i have to update it manually using session.getConnection and session.createSQLQuery() which is not elegent way of doint it .
Should i make a POJO for Student_course table also ???
If yes should it contain just the ID's (studentid , courseid ) along with marks or should it contain full student and course objects along with marks .
And how should the mapping file for this POJO say StudentCourse.hbm.xml look like
meaning what type of association should i use for
student and course properties of this class (Many-to-many , one-to-one , join etc ).
Thanks in advance for helping me .
Best Regards ,
Chandan Ahuja
|