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.