Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Object Relational Mapping and the fly likes Hibernate mapping problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "Hibernate mapping problem" Watch "Hibernate mapping problem" New topic
Author

Hibernate mapping problem

Vu Le
Greenhorn

Joined: Nov 08, 2006
Posts: 2
Hi, i have the following DB table, very simple

CLASS
-------
class_id
class_name


STUDENT
---------
student_id
student_name


STUDENT_STATUS
--------------
student_id
class_id
midterm_score
final_score


my mapping is as follow


The whole point is when a user click on any of the classes, an html table will show the list of students with their name, midterm score and final scores. I just start using Hibernate yesterday, and not sure how to fix the mapping to also retrieve the midterm_score and final_score. Any help is appreciated. Thank you

[ Edited to include code tags - Paul Sturrock ]
[ November 09, 2006: Message edited by: Paul Sturrock ]
Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 215
hi le i think you should add the many-to-many relation tag

attribute for the student table .and then you have to use

the link table properly .i think its better to play

with one-to-many in the initial stage.

regards
amir
Vu Le
Greenhorn

Joined: Nov 08, 2006
Posts: 2
I was thinking of breaking up the STUDENT_STATUS table into:

STUDENT_STATUS
--------------
student_id
class_id
entry_id (Primary Key)


STATUS
------------
entry_id (Primary Key)
midterm_score
final_score


... and use one-to-one mapping. I think it will work but just a waste to have another table just for hibernate to work. Does anyone has a solution to not having to split the table. Thank you
Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 215
well le

you can try with this set-up

two tables having primary and foregin key each other

(i.e) table1 Pk is FK in table2
and table1 FK is PK in table2


regards
amir
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Hibernate mapping problem
 
Similar Threads
Bi-directional mapping problems while creating tables on runtime
problem with hibernate mapping
Bi-directional mapping problems while creating tables on runtime
Bad cascade
Exception when having different class and table name