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: Mapping question
PostPosted: Fri Sep 15, 2006 2:24 am 
Newbie

Joined: Fri Sep 15, 2006 2:15 am
Posts: 2
I'm new to Hibernate so I feel some difficulties with mapping of these tables:

FORM {FORM_ID, DESCRIPTION,...},
QUESTION {QUESTION_ID, DESCRIPTION,...},
QUESTION_GROUP {GROUP_ID, DESCRIPTION,...},
FORM_QUESTION {FORM_ID, QUESTION_ID, GROUP_ID}

As you can see the last table is not business entity but relation table (FORM_ID & QUESTION_ID are Primary Key, GROUP_ID is FK).

How should I map my entities Form, Question & QuestionGroup? Should I create some 'FormQuestion' entity? I wouldn't like to do it..

Thanks for any advice.


Top
 Profile  
 
 Post subject: Re: Mapping question
PostPosted: Fri Sep 15, 2006 3:05 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Page wrote:
I'm new to Hibernate so I feel some difficulties with mapping of these tables:

FORM {FORM_ID, DESCRIPTION,...},
QUESTION {QUESTION_ID, DESCRIPTION,...},
QUESTION_GROUP {GROUP_ID, DESCRIPTION,...},
FORM_QUESTION {FORM_ID, QUESTION_ID, GROUP_ID}

As you can see the last table is not business entity but relation table (FORM_ID & QUESTION_ID are Primary Key, GROUP_ID is FK).

How should I map my entities Form, Question & QuestionGroup? Should I create some 'FormQuestion' entity? I wouldn't like to do it..


If You do not create 'FormQuestion' entity, how would You gain access to Group_Id (in code)? In UML world, the FormQAuestion could be association class

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 15, 2006 3:21 am 
Newbie

Joined: Fri Sep 15, 2006 2:15 am
Posts: 2
Oh, yes.. I see now...

And what about the relation table which contains only composite PK fields?
For ex. QUESTION_ID, FORM_ID & GROUP_ID fields are PK?

Thanks for response


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 15, 2006 3:33 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Page wrote:
And what about the relation table which contains only composite PK fields?
For ex. QUESTION_ID, FORM_ID & GROUP_ID fields are PK?


From code point of view, without association class it would mean something like

Code:
class Form
{
IList<Question> Questions;
IList<QuestionGroup> QuestionGroups;
}

class Question
{
IList<Form> Forms;
IList<QuestionGroup> QuestionGroups;
}

class QuestionGroup
{
IList<Form> Forms;
IList<Question> Questions;
}


How could You understand that for given form, in which group the question number 0 belongs to?

Edit: Not to mention that above class structure would be impossible to map into proposed table.

Gert

_________________
If a reply helps You, rate it!


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.