-->
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: hibernate mapping problem
PostPosted: Fri Feb 25, 2011 1:58 am 
Newbie

Joined: Fri Feb 25, 2011 1:37 am
Posts: 11
I have a table
trait_dictionary_mst which has
crop_id,crop_name,user_id fields

and there is another table trait_dictionary_dtl which has
crop_id,trait_name,trait_value,upperlimit,lowerlimit,trait_desc,default_value,trait_order

crop_id in trait_dictionary_dtl has foreign key reference in crop_id in trait_dictionary_mst
here is my hbm file for both tables
<hibernate-mapping>
<class name="TraitMaster" table="trait_dictionary_mst">
<id name="cropId" type="string">
<column name="CROP_ID" />
</id>
<property name="cropName" type="string" column="CROP_NAME" />
<bag name="traitDtls" lazy="true"
fetch="select">
<key>
<column name="CROP_ID"/>
</key>
<one-to-many class="org.hibernate.tutorial.domain.TraitDi" />
</bag>
</class>

</hibernate-mapping>

<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="TraitDi" table="trait_dictionary_dtl">
<id name="cropId" type="string">
<column name="CROP_ID" />
</id>
<property name="traitName" type="string" column="TRAIT_NAME"/>
<property name="traitValue" type="string" column="TRAIT_VALUE"/>
<property name="upperLImit" type="float" column="UPPERLIMIT"/>
<property name="lowerLImit" type="float" column="LOWERLIMIT"/>
<property name="traitDEsc" type="string" column="TRAIT_DESC"/>
<property name="defaultValue" type="string" column="DEFAULT_VALUE"/>
<property name="traitOrder" type="integer" column="TRAIT_ORDER"/>
</class>

</hibernate-mapping>

and java class for trait_dictionary_mst

public class TraitMaster {

private String cropId;
private String cropName;
private List<TraitDi> traitDtls;


public String getCropId() {
return cropId;
}
public void setCropId(String cropId) {
this.cropId = cropId;
}
public String getCropName() {
return cropName;
}
public void setCropName(String cropName) {
this.cropName = cropName;
}
public List<TraitDi> getTraitDtls() {
return traitDtls;
}
public void setTraitDtls(List<TraitDi> traitDtls) {
this.traitDtls = traitDtls;
}


}

so whenever is load the trait_dictionary_mst i should also get list of values of data from trait_dictionary_dtl

TraitMaster master = (TraitMaster) session.load(TraitMaster.class,
cropId);

List<TraitDi> list = master.getTraitDtls();
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
TraitDi traitDi = (TraitDi) iterator.next();
System.out.println(traitDi.getTraitName());
System.out.println(traitDi.getUpperLImit());
}
am getting the values from db but am getting wrong data

data present in db
CROP_ID,TRAIT_NAME,TRAIT_VALUE,UPPERLIMIT,LOWERLIMIT,TRAIT_DESC,DEFAULT_VALUE,TRAIT_ORDER
Ri,ricetrait2,,250.00,10.00,Trait2 description,200.0,30
Ri,ricetrait3,t3val1,0.00,0.00,Trait3 description,t3val2,31
Ri,ricetrait3,t3val2,0.00,0.00,Trait3 description,t3val2,32
Ri,ricetrait3,t3val3,0.00,0.00,Trait3 description,t3val2,33
Ri,ricetrait1,,10.00,2.00,Trait1 description,5.0,37
Ri,hibernate1,,0.00,0.00,,,38
Ri,hibernate2,,0.00,0.00,,,38
Ri,hibernate3,,0.00,0.00,,,38
Ri,hibernate4,,0.00,0.00,,,38

as u can see i have 7 different traitname

when i run the java i get all trait names as ricetrait2

is this problem due to trait_dictionary_dtl has no primary key well i can even make any key as primary key
bcoz trait_name can be same as u see in above data and each trait may have trait_value or it my have upperlimit or lower limit please help me to resolve 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.