These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Help Me in Modelling the information in Association table.
PostPosted: Tue Jul 03, 2007 8:42 am 
Newbie

Joined: Tue Jun 26, 2007 4:07 am
Posts: 5
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.