-->
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.  [ 5 posts ] 
Author Message
 Post subject: Collection table key
PostPosted: Thu Oct 02, 2003 3:42 pm 
Beginner
Beginner

Joined: Mon Sep 29, 2003 3:10 pm
Posts: 36
I have a many-to-many relationship in my application (between Assessments and QuestionGroups) that I expressed in the following manner:
<list
name="questionGroups"
table="Assessment_QuestionGroup"
lazy="true"
cascade="all" >

<key column="assessmentID"/>

<index column="ordinal"/>

<many-to-many class="com.xxx.QuestionGroup"
column="questionGroupID"
/>
</list>

When I use the schemaexport tool my associative table looks almost exactly as one would expect:

create table Assessment_QuestionGroup (
assessmentID BIGINT not null,
questionGroupID BIGINT not null,
ordinal INTEGER not null,
primary key (assessmentID, ordinal)
);

The things that stands out to me is that instead of the key being made up of a composite of "assessmentID" and "questionGroupID", the schemaexport tool pairs up the "assessmentID" with "ordinal".

I have some experience in DB design but I'm certainly no expert. That said, this seems a bit odd to me. Obviously, in terms of being unique, assessmentID/ordinal pair will certainly work, but then again, if we're following that line of thinking, so would the ordinal alone.

Does anyone know why this pairing was chosen? If it is indeed the better way to do things, I'd love to know so that I can ensure that my non-hibernate data models follow a similar pattern.

-Matt Welch


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 4:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ordinal is not unique on its own! There can be multiple lists, all with the same indexes.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 4:49 pm 
Beginner
Beginner

Joined: Mon Sep 29, 2003 3:10 pm
Posts: 36
You're right, of course. Please forgive my temporary lapse of intelligence, however, my main question remains. Why did the schemaexport tool use assessmentID/ordinal as the primary key instead of of assessmentID/questionGroupID?

-Matt Welch


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 5:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
because list semantics permit an object to belong twice to the list.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 5:53 pm 
Beginner
Beginner

Joined: Mon Sep 29, 2003 3:10 pm
Posts: 36
I had to really think about that one for a second to understand what you were saying, but I believe I 've got it.

Thanks.

-Matt Welch

[/code]


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