-->
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: using <map> question
PostPosted: Wed Sep 21, 2005 8:09 am 
Beginner
Beginner

Joined: Tue Aug 23, 2005 8:15 am
Posts: 45
I have the following classes(tables).
They represents Forms, Questions and
Questions which are included in some Forms.

The class Question has property Name, it represents
a short name of a questions.

Could you please help me to understand
how can I create in class Form
the map "QuestionBy" which maps Name -> Question for a given FormID.

I surfed the Web for examples and documentation
but did'nt fin anything useful.

Thank you!

Sergey





Form
{
FormID
Type
}


Question2Form
{
QuestionID
FormID
Sequence
}

Question
{
QuestionID
Name
Text
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 5:49 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
From what you describe I guess you have a many-to-many relationship between Form and Question tables. Look in the documentation for many-to-many associations. Basically, your mapping will look like this:
Code:
<class name="Form" table="Form">
...
<bag name="Questions" table="Question2Form">
      <key column="FormID"/>
      <many-to-many class="Question" column="QuestionID"/>
</bag>
...
</class>


Depending on the type of association: unidirectional or bidirectional you will have to set other attributes like "lazy", "cascade" etc. Again, look in the documentation

Regards,
Radu


Top
 Profile  
 
 Post subject: Thank you, radu but..
PostPosted: Mon Sep 26, 2005 2:57 pm 
Beginner
Beginner

Joined: Tue Aug 23, 2005 8:15 am
Posts: 45
I meaned some other think.
How can I use the MAP: QuestionName->Question
something like:

Form form;
((Question)form.QuestionByName["AGE"]).Text="How old are you?"




radu wrote:
From what you describe I guess you have a many-to-many relationship between Form and Question tables. Look in the documentation for many-to-many associations. Basically, your mapping will look like this:
Code:
<class name="Form" table="Form">
...
<bag name="Questions" table="Question2Form">
      <key column="FormID"/>
      <many-to-many class="Question" column="QuestionID"/>
</bag>
...
</class>


Depending on the type of association: unidirectional or bidirectional you will have to set other attributes like "lazy", "cascade" etc. Again, look in the documentation

Regards,
Radu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 7:38 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
I think you should use a HQL query to retrieve your question. Another approach is to use brute force: iterate the question list and return the question which match your criteria.

Radu


Top
 Profile  
 
 Post subject: And what about <map>?
PostPosted: Tue Sep 27, 2005 5:22 pm 
Beginner
Beginner

Joined: Tue Aug 23, 2005 8:15 am
Posts: 45
What for does it exist in hibrnate?


Thank you!

radu wrote:
I think you should use a HQL query to retrieve your question. Another approach is to use brute force: iterate the question list and return the question which match your criteria.

Radu


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.