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: Association returns null Set even though records exist
PostPosted: Tue Sep 19, 2006 3:19 pm 
Newbie

Joined: Mon Aug 07, 2006 2:08 am
Posts: 5
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....


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.