Hibernate version: 2.0
Name and version of the database you are using: postgres2.0
Hi,
I am trying to use the hibernate Inheritance mapping concepts to solve a scenerio in our application ,but am stuck at one scenerio.
Our application has two (2) level of Software Requirements defined as Level1Requirements and Level2Requirements, now Level2Requirements has all the fields that Level1Requirements has, so i have defined a Level1Requirements class and created Level2Requirements class by extending Level1Requirements, the only difference being the fact that Level2Requirements has a feild called parentID which contains the ID of the Level1Requirements requirement for which Level2Requirements has been created.The mapping document is given below.
Code:
<hibernate-mapping>
<class name="com.rohit.productbacklog.requirement.Leve1Requirement" table="vc_productbacklog" discriminator-value="LEVEL1">
<id name="reqId" type="long">
<generator class="native"/>
</id>
<discriminator column="level_type" type="string" length="15"/>
<property column="req_name" name="name" type="string"/>
<property column="req_desc" name="desc" type="string" />
<property name="scope" type="string" />
<property name="risk" type="string" />
<set name="tasks" cascade="all" inverse="true" lazy="true">
<key column="reqId"></key>
<one-to-many class="com.rohit.iterationbacklog.task.Task"/>
</set>
<subclass name="com.rohit.productbacklog.requirement.Level2Requirement" discriminator-value="LEVEL2">
<property name="parenId" column="parenId"/>
</subclass>
</class>
</hibernate-mapping>
Now the problem is that I want a one-to many and inverse(many-to-one) relationship between Level1Requirement and Level2Requirement, how do i achieve this. I tried making the following changes in the above mapping file but that didnt work.
Code:
<hibernate-mapping>
<class name="com.rohit.productbacklog.requirement.Leve1Requirement" table="vc_productbacklog" discriminator-value="LEVEL1">
<id name="reqId" type="long">
<generator class="native"/>
</id>
<discriminator column="level_type" type="string" length="15"/>
<property column="req_name" name="name" type="string"/>
<property column="req_desc" name="desc" type="string" />
<property name="scope" type="string" />
<property name="risk" type="string" />
<set name="tasks" cascade="all" inverse="true" lazy="true">
<key column="reqId"></key>
[b]<one-to-many class="com.rohit.iterationbacklog.task.Task"/>[/b]
</set>
<subclass name="com.rohit.productbacklog.requirement.Level2Requirement" discriminator-value="LEVEL2">
<property name="parenId" column="parenId"/>
<many-to-one name="requirement" class="com.rohit.productbacklog.requirement.Leve1Requirement" column="parenId" insert="false" update="false"/>
</subclass>
</class>
</hibernate-mapping>
it would be nice if someone could suggest as to where I am going wrong.
Thanks,
Rohit