-->
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.  [ 1 post ] 
Author Message
 Post subject: Multi-level Mapping
PostPosted: Thu Feb 24, 2011 7:01 am 
Newbie

Joined: Thu Feb 24, 2011 6:58 am
Posts: 1
Hi All,

I got one problem in Hibernate mapping. Here's the sample structure of my existing code.

Code:
<class table="PARENT_TBL" name="com.ParentPojo" select-before-update="true">

      <composite-id name="parentCompositeId" class="com.ParentPojo$ParentCompositeId">
         <key-property name="intPK1" column="PARENT_PK_COL1_ID" type="integer" />
         <key-property name="intPK2" column="PARENT_PK_COL2_ID" type="integer" />
      </composite-id>

      <set name="child1mapping" table="CHILD_TBL" lazy="true" cascade="all" inverse="true">
         <key>
            <column name="PARENT_PK_COL1_ID" />
            <column name="PARENT_PK_COL2_ID" />
         </key>
         <one-to-many class="com.ChildPojo" />
      </set>

   </class>
   
   <class table="CHILD_TBL" name="com.ChildPojo">

      <composite-id name="childCompositeId" class="com.ChildPojo$ChildCompositeId">
         <key-property name="intPK1" column="PARENT_PK_COL1_ID" type="integer" />
         <key-property name="intPK2" column="PARENT_PK_COL2_ID" type="integer" />
         <key-property name="intPK3" column="CHILD_PK_COL3_ID" type="integer" />
      </composite-id>

      <set name="subChildLvl" table="SUB_CHILD_TBL" lazy="true" cascade="all" inverse="true">
         <key>
            <column name="PARENT_PK_COL1_ID" />
            <column name="PARENT_PK_COL2_ID" />
            <column name="CHILD_PK_COL3_ID" />
         </key>
         <one-to-many class="com.Child2Pojo" />
      </set>

   </class>

   <class table="SUB_CHILD_TBL" name="com.subChildPojo">

      <composite-id name="subChildCompositeId" class="com.SubChildPojo$SubChildCompositeId">
         <key-property name="intPK1" column="PARENT_PK_COL1_ID" type="integer" />
         <key-property name="intPK2" column="PARENT_PK_COL2_ID" type="integer" />
         <key-property name="intPK3" column="CHILD_PK_COL3_ID" type="integer" />
         <key-property name="intPK4" column="SUB_CHILD_PK_COL4_ID" type="integer" />
      </composite-id>

   </class>


Problem
-------
The table SUB_CHILD_TBL wants tobe mapped in both CHILD_TBL & PARENT_TBL.
When we are doing like that, in parent level we will be inserting "*" in the column "CHILD_PK_COL3_ID" in SUB_CHILD_TBL .
In Child level we will be inseting CHILD_PK_COL3_ID of CHILD_TBL to SUB_CHILD_TBL. We tried to map like the following;

Code:
<class table="PARENT_TBL" name="com.ParentPojo" select-before-update="true">

      <composite-id name="parentCompositeId" class="com.ParentPojo$ParentCompositeId">
         <key-property name="intPK1" column="PARENT_PK_COL1_ID" type="integer" />
         <key-property name="intPK2" column="PARENT_PK_COL2_ID" type="integer" />
      </composite-id>

      <set name="childmapping" table="CHILD_TBL" lazy="true" cascade="all" inverse="true">
         <key>
            <column name="PARENT_PK_COL1_ID" />
            <column name="PARENT_PK_COL2_ID" />
         </key>
         <one-to-many class="com.ChildPojo" />
      </set>

      <set name="subChildmapping" table="SUB_CHILD_TBL" lazy="true" cascade="all" inverse="true">
         <key>
            <column name="PARENT_PK_COL1_ID" />
            <column name="PARENT_PK_COL2_ID" />
         </key>
         <one-to-many class="com.subChildPojo" />
      </set>

   </class>


When we trying this, we are getting all the records. Actually we should get only the "*" records.
In the Mapping we didn't gave the "CHILD_PK_COL3_ID" column. So it's retriving all the records.

Can any one tell me, how to solve this problem?.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.