Hi,
I generated my Hibernate mapping documents using Middlegen, middlegen generates separate classes for the composite keys. I have a one-to-many association between 2 tables, both these tables have composite primary keys and hence their own individual primary key classes. Records from the second class (the many side of the relationship) are stored in a set of the POJO of the first table. The problem is that a zero element set is being returned even though matchign record exist in the second table. Plz refer to the code below,
Table 1 mapping doc, (the part of it which maps to the primary key class)
<class name="com.bofa.crme.msb.bom.wrk.WrkDealEqAsHg" table="WRK_DEAL_EQ_AS_HG" >
<composite-id name="comp_id" class="com.bofa.crme.msb.bom.wrk.WrkDealEqAsHgPK"> <key-property name="internalDealId" column="INTERNAL_DEAL_ID" type="java.math.BigDecimal" length="22" /> <key-property name="prodLev1" column="PROD_LEV1" type="java.lang.String" length="45" /> <key-property name="prodLev2" column="PROD_LEV2" type="java.lang.String" length="45" /> </composite-id>
Association with the second table is as below,
<!-- Associations --> <!-- derived association(s) for compound key --> <!-- end of derived association(s) --> <!-- bi-directional one-to-many association to WrkMgrEqAsHg --> <set name="wrkMgrEqAsHgs" lazy="true" inverse="true" cascade="none" > <key> <column name="INTERNAL_DEAL_ID" /> <column name="PROD_LEV2" /> <column name="PROD_LEV1" /> </key> <one-to-many class="com.bofa.crme.msb.bom.wrk.WrkMgrEqAsHg" /> </set>
Table 1 mapping doc, (the part of it which maps to the primary key class)
<class name="com.bofa.crme.msb.bom.wrk.WrkMgrEqAsHg" table="WRK_MGR_EQ_AS_HG" >
<composite-id name="comp_id" class="com.bofa.crme.msb.bom.wrk.WrkMgrEqAsHgPK"> <key-property name="internalDealId" column="INTERNAL_DEAL_ID" type="java.math.BigDecimal" length="22" /> <key-property name="managerCode" column="MANAGER_CODE" type="java.lang.String" length="50" /> <key-property name="managerRole" column="MANAGER_ROLE" type="java.lang.String" length="50" /> <key-property name="prodLev1" column="PROD_LEV1" type="java.lang.String" length="45" /> <key-property name="prodLev2" column="PROD_LEV2" type="java.lang.String" length="45" /> </composite-id>
Table 2 Other side of the association,
<many-to-one name="wrkDealEqAsHg" class="com.bofa.crme.msb.bom.wrk.WrkDealEqAsHg" update="false" insert="false" > <column name="INTERNAL_DEAL_ID" /> <column name="PROD_LEV2" /> <column name="PROD_LEV1" /> </many-to-one> <!-- end of derived association(s) -->
When I try to access the Set "wrkMgrEqAsHgs" from a business class as below I get a set with no elements even though matching records exists in the database. I am using the same equals and hashcode methods provided when the mapping docs were generated by middlegen,
WrkDealEqAsHg aWrkDealEqAsHg = new WrkDealEqAsHg(); WrkDealEqAsHgPK aWrkDealEqAsHgPK = new WrkDealEqAsHgPK(); aWrkDealEqAsHgPK.setInternalDealId(new BigDecimal(123456)); aWrkDealEqAsHgPK.setProdLev1("Test1"); aWrkDealEqAsHgPK.setProdLev2("Test2"); aWrkDealEqAsHg.setComp_id(aWrkDealEqAsHgPK); session.refresh(aWrkDealEqAsHg); System.out.println("The size is -------------------> " + aWrkDealEqAsHg.getWrkMgrEqAsHgs().size());
I get the size of the set as zero, worse if i dont refresh the object in the session before retrieving the Set then I get a null pointer exception. Any idea on wats happening? Thanks in advance....
|