-->
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.  [ 2 posts ] 
Author Message
 Post subject: Please Help me in understanding hibernate.
PostPosted: Mon Nov 20, 2006 3:24 am 
Newbie

Joined: Mon Nov 20, 2006 2:12 am
Posts: 8
Location: Gurgaun
I am a very beginner in Hibernate.
I have a scenario.
Please Guide me.

there are three tables questions, answers, and options.

I want to map question class to answer class, and opions class.

The Scenario is: I am mapping question to options, by set element one-to-many collection mapping. option in turn is mapped to answer class by one-to-one mapping. Then question class is again mapped to answer class by one-to-one mapping.

The confusion is: I have read in the documentation, that collection is a value type(not entity type), and can't be associated with more than one entity.
Does that mean I will not be able to form one to one (by using component element) relation between the option and answer, as option is mapped as collection in question.

I am very new to this technology. Please guide me.

The mapping is as follows:
Code:
<hibernate-mapping>
  <class name="Question">
    <id name="qId">
      <generator class="native"/>
    </id>
    <property name="desc" />
    <set name="options" >
      <key column="qid" />
      <one-to-many class="Option" />
    </set>
    <component name="Answer" unique="true">
      <key column="aId" />
      <property name="desc" length="20"/>
      <property name="longdesc" />
    </component>
  </class>

  <class name="Option">
    <id name="qId">
      <generator class="native" />
    </id>
    <component name="Answer" unique="true">
      <key column="aId" />
      <property name="desc" length="20" />
      <property name="longdesc" />
    </component>
  </class>

  <class name="Answer">
    <id name="qId">
     <generator class="native" />
    </id>
      <property name="desc" length="20" />
      <property name="longdesc" />
    </component>
  </class>
<hibernate-mapping>


Please guide me where I am wrong in this mapping, or what are the alternatives I can apply here.

_________________
Thanks & Regards
Sumit Tyagi.


Top
 Profile  
 
 Post subject: problem solved
PostPosted: Mon Nov 20, 2006 8:41 am 
Newbie

Joined: Mon Nov 20, 2006 2:12 am
Posts: 8
Location: Gurgaun
I think This will solve my problem:

Please comment on it.

Code:
<hibernate-mapping>
  <class name="Question">
    <id name="questionId" column="question_id">
      <generator class="native"/>
    </id>
    <property name="desc" />
    <map name="options" table="answer_option">
      <key column="question_id" />
      <index column="option_name" type="string" />
      <many-to-many column="option_id" class="Answer" />
    </map>
    <many-to-one name="answer" class="Answer" column="answer_id" not-null="true" />
  </class>

  <class name="Answer">
    <id name="answerId" column="answer_id">
     <generator class="native" />
    </id>
    <property name="desc" length="20" />
    <property name="longDesc" column="long_desc" />
  </class>
</hibernate-mapping>


Please comment and
Please guide me, if there is any better way.

_________________
Thanks & Regards
Sumit Tyagi.


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