-->
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.  [ 4 posts ] 
Author Message
 Post subject: Need Help to define relation ships among tables
PostPosted: Wed Sep 13, 2006 3:20 am 
Newbie

Joined: Wed Sep 13, 2006 2:44 am
Posts: 2
Location: chennai
How do we represent the following relationships in hibernate.

Here OrganizationExamSource table have a composite primary key.
each of the columns(organizationId and examSourceId ) are the primary keys of other two tables

OrganizationExamSource (
organizationId BIGINT NOT NULL REFERENCES Organization(organizationId),
examSourceId BIGINT NOT NULL REFERENCES ExamSource(examsourcerecordId),
noAccess int NOT NULL DEFAULT 0,
PRIMARY KEY (organizationId, examSourceId)
);


Organization (
organizationId BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, -- auto generated interal ID
parentId BIGINT REFERENCES Organization(organizationId),
orgName VARCHAR(255) NOT NULL,
address1 VARCHAR(255)
address2 VARCHAR(255)
orgDesc TEXT, -- description
UNIQUE INDEX (parentId, orgName) -- ensure names are unique at each level
);


ExamSource (
examsourcerecordId BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
sourceName VARCHAR (255) NOT NULL,
isActive INT NOT NULL DEFAULT 1,
UNIQUE INDEX (sourceName)
);[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 2:46 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
If your OrganizationExamSource is only an association table, you can use a many-to-many between Organization and ExamSource (http://www.hibernate.org/hib_docs/v3/reference/en/html/associations.html#assoc-bidirectional-join-m2m) and don't have to define a <class> for OrganizationExamSource.

But it looks like you have extra fields in the association table (e.g. 'noAccess'), so you probably want to set it up as two many-to-ones (http://www.hibernate.org/hib_docs/v3/reference/en/html/associations.html#assoc-bidirectional-m21).

So your OrganizationExamSource would have two <many-to-one> associations (to Organization and ExamSource), and Organization and ExamSource would each have a matching inverse <set> association.

Hope that helps.

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 2:51 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
I realized that I mis-spoke a little. I am used to always using surrogate keys. If you want your OrganizationExamSource primary key to be the two foreign key columns, instead of using <many-to-one> tags in the OrganizationExamSource class, you would use <key-many-to-one> inside the <composite-id> tag (http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html#mapping-declaration-compositeid).

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 11:39 pm 
Newbie

Joined: Wed Sep 13, 2006 2:44 am
Posts: 2
Location: chennai
Thanks Nathan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.