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?.