-->
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: [b]Need help with inheritance mapping.[/b]
PostPosted: Thu May 18, 2006 7:46 am 
Newbie

Joined: Thu May 18, 2006 6:36 am
Posts: 11
Location: Bangalore
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 18, 2006 12:02 pm 
Newbie

Joined: Wed Nov 02, 2005 1:17 pm
Posts: 13
Assuming your Level2Requirement java class contains an instance variable that looks something like:

Code:
private LevelRequirement parentID;


Your subclass definition should look something like;


Code:
   
<subclass name="com.rohit.productbacklog.requirement.Level2Requirement" discriminator-value="LEVEL2">
    <many-to-one name="parenID" column="PARENT_ID"/>
</subclass>


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.