-->
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.  [ 3 posts ] 
Author Message
 Post subject: Many to many mapping question
PostPosted: Thu Jan 13, 2011 5:13 pm 
Newbie

Joined: Thu Jan 13, 2011 5:02 pm
Posts: 2
I am new to hibernate and just recently i started looking in to the tutorial on it at http://docs.jboss.org/hibernate. So please bear with me.

I have a database tables Patient, Hospital and PatientHospital. My classes look somthing like this.

Patient { id (PK), firstname, lastname}
Hospital {id(PK), name, address}
PatientHospital{hospitalId (PK), patientId, recordNumber}

This is a many-to-many mapping. I am trying to map this on hibernate but have not been successful.

Do we need to create a hibernate mapping xml for PatientHospital as well?

Can anyone please help me out with the hibernate mapping? Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Many to many mapping question
PostPosted: Thu Jan 13, 2011 9:38 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Simplify and forget pointing to ids of other tables, point to references of other entities.
So turn:
Quote:
PatientHospital{hospitalId (PK), patientId, recordNumber}

into
Code:
PatientHospital{hospital, patient, recordNumber}

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Many to many mapping question
PostPosted: Thu Jan 13, 2011 11:35 pm 
Newbie

Joined: Thu Jan 13, 2011 5:02 pm
Posts: 2
Thanks SG but I dont understand what you are trying to say. My hospital and patient classes has a many to many relation and I needed to create that mapping table PatientHospital table. Can you explain it with a sample code.

My point is when I query for Patient it should bring me Patient and the hospital information and recordNumber. How can I create hibernate mapping for this?

As I said before I am very new to Hibernate. Just 2 days old.

Thanks.

SP


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

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.