My class RequestBean has one to many mapping with BalanceCertificate Class.I have one to many declartion in the hbm xml of RequestBean.The query is reurning one row.But when i load the object that is mapped in lazy i returns two rows for that collection.The criteria that was applied to the query is not getting applied when performing lazy load.How to avoid this?
Hibernate version: 3.0.5
Mapping documents: <hibernate-mapping>
<class name="cl.ing.coreafp.pension.request.beans.RequestBean"
table="s_request">
<id name="requestId" column="REQ_REQ_SUR_ID" type="int">
<generator class="sequence">
<param name="sequence">s_request_seq</param>
</generator>
</id>
<property name="requestReceivedMode" column="REQ_RCD_MOD_CR"
type="java.lang.String" />
<property name="officeNumber" column="REQ_RCD_OFN_NN"
type="int" />
<property name="officeDate" column="REQ_RCD_OFD_FC"
type="java.util.Date" />
<property name="countryOfAgreement" column="CC_COD_CR"
type="java.lang.String" />
<property name="requestFromAfp" column="REQ_OTR_AFP_CR"
type="java.lang.String" />
<property name="requestReceivedDate" column="REQ_RCD_DTE_FC"
type="java.util.Date" />
<property name="requestStatus" column="REQ_STA_CR"
type="java.lang.String" />
<property name="INGStaffId" column="EI_EID_ID" type="int" />
<property name="affiliateId" column="AFF_AFF_ID" type="int" />
<property name="branchCode" column="AB_COD_CR" type="java.lang.String" />
<!-- property name="createdBy" type="java.lang.String"
column="REQ_CRT_ID" not-null="false" length="50">
</property>
<property name="createdTimeStamp" type="java.util.Date"
column="REQ_CRT_FC" not-null="false" length="50">
</property>
<property name="modifiedBy" type="java.lang.String"
column="REQ_LST_UPD_ID" not-null="false" length="50">
</property>
<property name="modifiedTimeStamp" type="java.util.Date"
column="REQ_LST_UPD_FC" not-null="false" length="50">
</property-->
<joined-subclass
name="cl.ing.coreafp.pension.request.beans.PensionRequestBean"
table="s_pnsn_rqst">
<key column="REQ_REQ_SUR_ID" />
<property name="pensionStartDate" type="java.util.Date"
column="PRQ_PEN_STR_FC" length="50">
</property>
<property name="surplusRequestInd" column="PRQ_FUS_IND_RE"
type="short" />
<property name="pensionType" column="PRQ_STR_TYP_CR"
type="java.lang.String" />
<property name="penReqAcptDate" column="PRQ_ACP_DTE_FC"
type="java.util.Date" />
<property name="sinisterDate" column="PRQ_STR_DTE_FC"
type="java.util.Date" />
<property name="sharePublicInformationInd"
column="PRQ_PUB_IND_RE" type="short" not-null="true" />
<property name="agrdDpstInOthrAPVInd" type="short"
column="PRQ_AGD_IND_RE" length="50">
</property>
<property name="disabilityPensionInd"
column="PRQ_DSP_IND_RE" type="short" />
<property name="disabilityPensionFromAfp"
column="PRQ_DSP_AFP_CR" type="java.lang.String" />
<property name="govermentEmployeeIndicator"
column="PRQ_GVT_IND_RE" type="short" />
<property name="communicationMean" column="PRQ_COM_MNS_CR"
type="java.lang.String" />
<property name="thirdPartyRequest" column="PRQ_RSD_BY_CR"
type="java.lang.String" />
<property name="amtInAPVUsageInd" column="PRQ_APV_IND_RE"
type="short" />
<property name="contributedInOtherCountryInd"
column="PRQ_OCC_RE" type="short" />
<property name="contrLstTenYrsInd" column="PRQ_OSC_RE"
type="short" />
<property name="pensionerOldSystmInd" column="PRQ_OSP_RE"
type="short" />
<property name="pensionInOtherCountryInd"
column="PRQ_OCP_RE" type="short" />
<property name="affiliateId" column="AFF_AFF_ID"
type="int" />
<!-- property name="createdBy" type="java.lang.String"
column="PRQ_CRT_ID" not-null="false" length="50">
</property>
<property name="createdTimeStamp" type="java.util.Date"
column="PRQ_CRT_FC" not-null="false" length="50">
</property>
<property name="modifiedBy" type="java.lang.String"
column="PRQ_LST_UPD_ID" not-null="false" length="50">
</property>
<property name="modifiedTimeStamp" type="java.util.Date"
column="PRQ_LST_UPD_FC" not-null="false" length="50">
</property-->
<!-- <one-to-one name="objBalanceCertificateBean"
class="cl.ing.coreafp.pension.balancecertificate.beans.BalanceCertificateBean" property-ref="requestId" constrained="true" lazy="proxy" outer-join="false"/>-->
<!-- <many-to-one name="objBalanceCertificateBean" class="cl.ing.coreafp.pension.balancecertificate.beans.BalanceCertificateBean" column="REQ_REQ_SUR_ID"
unique="true" insert="false" update="false" cascade="all" /> -->
<set name="balanceCertificateList" cascade="all" lazy="true">
<key column="REQ_REQ_SUR_ID"/>
<one-to-many class="cl.ing.coreafp.pension.balancecertificate.beans.BalanceCertificateBean"></one-to-many>
</set>
<joined-subclass
name="cl.ing.coreafp.pension.request.beans.NormalPensionRequestBean"
table="S_NORML_PNSN_RQST">
<key column="REQ_REQ_SUR_ID" />
<property name="accrualDateOption"
column="NPR_ACD_OPT_CR" type="java.lang.String" />
<property name="preliminaryPaymentInd"
column="NPR_PRL_IND_RE" type="short" />
<property name="accrualDate" column="NPR_ACC_DTE_FC"
type="java.util.Date" />
<property name="volSvngUsageInd" column="NPR_VUS_IND_RE"
type="short" />
<property name="volSvngAmntInPesos"
column="NPR_VSP_AMT_$$" type="java.lang.Float" />
<property name="fundType1OfAccount2"
column="NPR_FTO_ACT_CR" type="char" />
<property name="fundType2OfAccount2"
column="NPR_FTT_ACT_CR" type="char" />
<property name="volSvngQuotesAmntInFund1"
column="NPR_VSA_FNO_$$" type="float" />
<property name="volSvngQuotesAmntInFund2"
column="NPR_VSA_FNT_$$" type="float" />
<property name="volConUsageInd" type="short"
column="NPR_VQI_IND_RE">
</property>
<property name="volConAmntInPesos"
column="NPR_VQP_AMT_$$" type="java.lang.Float" />
<property name="fundType1OfAccount4"
column="NPR_FTO_ACF_CR" type="char" />
<property name="fundType2OfAccount4"
column="NPR_FTT_ACF_CR" type="char" />
<property name="volConQuotesAmntInFund1"
column="NPR_VCA_FTO_$$" type="float" />
<property name="volConQuotesAmntInFund2"
column="NPR_VCA_FTT_$$" type="float" />
<property name="adjustToMinimumPensionInd"
column="NPR_MNP_IND_RE" type="short" />
<property name="APVTransactionid" column="NPR_AID_ID"
type="int" />
<property name="voluntarySocialSecurityTransactionId"
column="NPR_VID_ID" type="int" />
<!-- property name="createdBy" type="java.lang.String"
column="NPR_CRT_ID" not-null="false" length="50">
</property>
<property name="createdTimeStamp" type="java.util.Date"
column="NPR_CRT_FC" not-null="false" length="50">
</property>
<property name="modifiedBy" type="java.lang.String"
column="NPR_LST_UPD_ID" not-null="false" length="50">
</property>
<property name="modifiedTimeStamp" type="java.util.Date"
column="NPR_LST_UPD_FC" not-null="false" length="50">
</property-->
</joined-subclass>
</joined-subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Criteria criteria = session.createCriteria(RequestBean.class);
Criteria balcriteria= criteria.createCriteria("balanceCertificateList");
Criteria rejectionCauseCriteria=balcriteria.createCriteria("objBCRejectionCause");
Criteria rejectionCodeCriteria=rejectionCauseCriteria.createCriteria("objRejectionCodes");
criteria.add(Expression.eq("pensionType",objBalanceCertificateViewBean.getPensionType()));
if (!("0").equals(objBalanceCertificateViewBean.getAssistantName()))
balcriteria.add(Expression.eq("createdBy",
objBalanceCertificateViewBean.getAssistantName()));
if (!("0").equals(objBalanceCertificateViewBean.getStatus())) {
balcriteria.add(Expression.eq("certificateStatus", objBalanceCertificateViewBean.getStatus()));
}
if (objBalanceCertificateViewBean.getCreationDate() != null) {
balcriteria.add(Expression.eq("createdTimeStamp",
objBalanceCertificateViewBean.getCreationDate()));
}
objBalanceCertificateViewBean.setBalanceCertificateList(balanceCertificateList);
int x=objBalanceCertificateViewBean.getBalanceCertificateList().size();
for(int i=0;i<x;i++)
{
RequestBean objRequestBean=new RequestBean();
PensionRequestBean objPensionRequestBean =(PensionRequestBean)objBalanceCertificateViewBean.getBalanceCertificateList().get(i);
BalanceCertificateBean objBalanceCertificateBean=(BalanceCertificateBean)objPensionRequestBean.getBalanceCertificateList().iterator().next();
System.out.println("the status is"+objBalanceCertificateBean.getCertificateStatus());
BCRejectionCause objBCRejectionCause=(BCRejectionCause)objBalanceCertificateBean.getObjBCRejectionCause();
BCRejectionCodes objBCRejectionCodes=(BCRejectionCodes)objBCRejectionCause.getObjRejectionCodes();
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:oracle 9i
The generated SQL (show_sql=true):
select * from ( select this_.REQ_REQ_SUR_ID as REQ1_3_, this_.REQ_RCD_MOD_CR as REQ2_0_3_, this_.REQ_RCD_OFN_NN as REQ3_0_3_, this_.REQ_RCD_OFD_FC as REQ4_0_3_, this_.CC_COD_CR as CC5_0_3_, this_.REQ_OTR_AFP_CR as REQ6_0_3_, this_.REQ_RCD_DTE_FC as REQ7_0_3_, this_.REQ_STA_CR as REQ8_0_3_, this_.EI_EID_ID as EI9_0_3_, this_.AFF_AFF_ID as AFF10_0_3_, this_.AB_COD_CR as AB11_0_3_, this_1_.PRQ_PEN_STR_FC as PRQ2_1_3_, this_1_.PRQ_FUS_IND_RE as PRQ3_1_3_, this_1_.PRQ_STR_TYP_CR as PRQ4_1_3_, this_1_.PRQ_ACP_DTE_FC as PRQ5_1_3_, this_1_.PRQ_STR_DTE_FC as PRQ6_1_3_, this_1_.PRQ_PUB_IND_RE as PRQ7_1_3_, this_1_.PRQ_AGD_IND_RE as PRQ8_1_3_, this_1_.PRQ_DSP_IND_RE as PRQ9_1_3_, this_1_.PRQ_DSP_AFP_CR as PRQ10_1_3_, this_1_.PRQ_GVT_IND_RE as PRQ11_1_3_, this_1_.PRQ_COM_MNS_CR as PRQ12_1_3_, this_1_.PRQ_RSD_BY_CR as PRQ13_1_3_, this_1_.PRQ_APV_IND_RE as PRQ14_1_3_, this_1_.PRQ_OCC_RE as PRQ15_1_3_, this_1_.PRQ_OSC_RE as PRQ16_1_3_, this_1_.PRQ_OSP_RE as PRQ17_1_3_, this_1_.PRQ_OCP_RE as PRQ18_1_3_, this_1_.AFF_AFF_ID as AFF19_1_3_, this_2_.NPR_ACD_OPT_CR as NPR2_2_3_, this_2_.NPR_PRL_IND_RE as NPR3_2_3_, this_2_.NPR_ACC_DTE_FC as NPR4_2_3_, this_2_.NPR_VUS_IND_RE as NPR5_2_3_, this_2_.NPR_VSP_AMT_$$ as NPR6_2_3_, this_2_.NPR_FTO_ACT_CR as NPR7_2_3_, this_2_.NPR_FTT_ACT_CR as NPR8_2_3_, this_2_.NPR_VSA_FNO_$$ as NPR9_2_3_, this_2_.NPR_VSA_FNT_$$ as NPR10_2_3_, this_2_.NPR_VQI_IND_RE as NPR11_2_3_, this_2_.NPR_VQP_AMT_$$ as NPR12_2_3_, this_2_.NPR_FTO_ACF_CR as NPR13_2_3_, this_2_.NPR_FTT_ACF_CR as NPR14_2_3_, this_2_.NPR_VCA_FTO_$$ as NPR15_2_3_, this_2_.NPR_VCA_FTT_$$ as NPR16_2_3_, this_2_.NPR_MNP_IND_RE as NPR17_2_3_, this_2_.NPR_AID_ID as NPR18_2_3_, this_2_.NPR_VID_ID as NPR19_2_3_, case when this_2_.REQ_REQ_SUR_ID is not null then 2 when this_1_.REQ_REQ_SUR_ID is not null then 1 when this_.REQ_REQ_SUR_ID is not null then 0 end as clazz_3_, balancecer1_.BCC_BCC_SUR_ID as BCC1_0_, balancecer1_.BCC_STA_CR as BCC2_6_0_, balancecer1_.BCC_ISS_DTE_FC as BCC3_6_0_, balancecer1_.BCC_EXP_DTE_FC as BCC4_6_0_, balancecer1_.BCC_CLO_DTE_FC as BCC5_6_0_, balancecer1_.REQ_REQ_SUR_ID as REQ6_6_0_, balancecer1_.BCC_DEV_DTE_FC as BCC7_6_0_, balancecer1_.BCC_FOL_NN as BCC8_6_0_, balancecer1_.BCC_CRT_ID as BCC9_6_0_, balancecer1_.BCC_CRT_FC as BCC10_6_0_, balancecer1_.BCC_LST_UPD_ID as BCC11_6_0_, balancecer1_.BCC_LST_UPD_FC as BCC12_6_0_, bcrejectio2_.BRE_BRE_SUR_ID as BRE1_1_, bcrejectio2_.BRE_REJ_COM_CR as BRE2_7_1_, bcrejectio2_.BCC_BCC_SUR_ID as BCC3_7_1_, bcrejectio2_.BRE_CRT_ID as BRE4_7_1_, bcrejectio2_.BRE_CRT_FC as BRE5_7_1_, bcrejectio2_.BRE_LST_UPD_ID as BRE6_7_1_, bcrejectio2_.BRE_LST_UPD_FC as BRE7_7_1_, bcrejectio2_.BRC_BRC_SUR_ID as BRC8_7_1_, bcrejectio3_.BRC_BRC_SUR_ID as BRC1_2_, bcrejectio3_.BRC_BRN_CDE_NN as BRC2_8_2_, bcrejectio3_.BRC_DES_CR as BRC3_8_2_, bcrejectio3_.BRC_VLD_BYF_CR as BRC4_8_2_, bcrejectio3_.BRC_CRT_ID as BRC5_8_2_, bcrejectio3_.BRC_CRT_FC as BRC6_8_2_, bcrejectio3_.BRC_LST_UPD_ID as BRC7_8_2_, bcrejectio3_.BRC_LST_UPD_FC as BRC8_8_2_ from s_request this_ left outer join s_pnsn_rqst this_1_ on this_.REQ_REQ_SUR_ID=this_1_.REQ_REQ_SUR_ID left outer join S_NORML_PNSN_RQST this_2_ on this_.REQ_REQ_SUR_ID=this_2_.REQ_REQ_SUR_ID inner join s_balance_cert balancecer1_ on this_.REQ_REQ_SUR_ID=balancecer1_.REQ_REQ_SUR_ID inner join s_bcrejection_cause bcrejectio2_ on balancecer1_.BCC_BCC_SUR_ID=bcrejectio2_.BCC_BCC_SUR_ID inner join s_bcrejection_code bcrejectio3_ on bcrejectio2_.BRC_BRC_SUR_ID=bcrejectio3_.BRC_BRC_SUR_ID where this_1_.PRQ_STR_TYP_CR=? and balancecer1_.BCC_STA_CR=? ) where rownum <= ?
select balancecer0_.REQ_REQ_SUR_ID as REQ6_1_, balancecer0_.BCC_BCC_SUR_ID as BCC1_1_, balancecer0_.BCC_BCC_SUR_ID as BCC1_0_, balancecer0_.BCC_STA_CR as BCC2_6_0_, balancecer0_.BCC_ISS_DTE_FC as BCC3_6_0_, balancecer0_.BCC_EXP_DTE_FC as BCC4_6_0_, balancecer0_.BCC_CLO_DTE_FC as BCC5_6_0_, balancecer0_.REQ_REQ_SUR_ID as REQ6_6_0_, balancecer0_.BCC_DEV_DTE_FC as BCC7_6_0_, balancecer0_.BCC_FOL_NN as BCC8_6_0_, balancecer0_.BCC_CRT_ID as BCC9_6_0_, balancecer0_.BCC_CRT_FC as BCC10_6_0_, balancecer0_.BCC_LST_UPD_ID as BCC11_6_0_, balancecer0_.BCC_LST_UPD_FC as BCC12_6_0_ from s_balance_cert balancecer0_ where balancecer0_.REQ_REQ_SUR_ID=?
select bcrejectio0_.BRE_BRE_SUR_ID as BRE1_0_, bcrejectio0_.BRE_REJ_COM_CR as BRE2_7_0_, bcrejectio0_.BCC_BCC_SUR_ID as BCC3_7_0_, bcrejectio0_.BRE_CRT_ID as BRE4_7_0_, bcrejectio0_.BRE_CRT_FC as BRE5_7_0_, bcrejectio0_.BRE_LST_UPD_ID as BRE6_7_0_, bcrejectio0_.BRE_LST_UPD_FC as BRE7_7_0_, bcrejectio0_.BRC_BRC_SUR_ID as BRC8_7_0_ from s_bcrejection_cause bcrejectio0_ where bcrejectio0_.BCC_BCC_SUR_ID=?
Debug level Hibernate log excerpt:
|