Hibernate 3.1.3 PsotgreSQL
Company.hbm
<set name="commissions" batch-size = "20" outer-join = "true" cascade="all, delete-orphan" >
<key column="company_id"/>
<one-to-many class="CompanyCommissions"/>
</set>
CompanyCommissions.hbm
<many-to-one name= "company" column = "company_id" cascade="none" not-null="true"/>
<property name="planType" column = "plan_type"/>
<set name="commissiondetails" batch-size = "20" cascade="all, delete-orphan" inverse = "false" >
<key column="commission_id"/>
<one-to-many class="CompanyCommissionDetails"/>
</set>
CompanyCommissionDetails.hbm
<hibernate-mapping>
<class name="CompanyCommissionDetails" table="tdat_company_commission_details">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="companyCommissionDetailId" type="long" unsaved-value="0">
<column name="comp_commission_detail_id" sql-type="serial" not-null="true"/>
<generator class="sequence">
<param name="sequence">tdat_company_commission_details_comp_commission_detail_id_seq</param>
</generator>
</id>
<many-to-one name= "commission" column="commission_id" cascade="none" not-null="true" />
<property name= "rateType" column="rate_type"/>
<property name= "value"/>
<property name= "endRate" column="end_rate"/>
</class>
</hibernate-mapping>
Java Code:
cc = (Company)sess.load(Company.class,cc.getCompanyId());
Hibernate.initialize(cc);
if(cc.getCommissions().size() >= 1){
commissions = cc.getCommissions();
for(Iterator i = commissions.iterator(); i.hasNext();){
CompanyCommissions companycommission = (CompanyCommissions) i.next();
if(companycommission.getPlanType() == 0){
details = companycommission.getCommissiondetails();
System.out.println(details.size());
for(Iterator ii = details.iterator(); ii.hasNext();){
Vector rowData = new Vector();
System.out.println("CHECK1");
CompanyCommissionDetails commissiondetails = (CompanyCommissionDetails) ii.next();
if(commissiondetails.getRateType() == 0) { // hourly rate
rowData.add(commissiondetails.getEndRate());
rowData.add(commissiondetails.getValue());
rateModel.addRow(rowData);
System.out.println("CHECK2");
}
else if(commissiondetails.getRateType() == 1){
rowData.add(commissiondetails.getEndRate());
rowData.add(commissiondetails.getValue());
salesModel.addRow(rowData);
}
}
rateModel.fireTableDataChanged();
salesModel.fireTableDataChanged();
}
I have a company object which has set of companycommissions and each companycommissions can have multiple companycommission details.
When I load the company object, I could set my companycommission set having values but the companycommissiondetails set within my commissions is empty.
I am struggling with this problem. Could some one tell me if my mapping file has got any problem. Why is my commissiondetials collection not getting loaded when I access my company object. When I debugged, my companycommissions set is empty.
|