1.hibernate xml
<?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping>
     <class name="com.citi.apollo.fmk.model.PvTrs" table="PVTRS" schema="GCD"
      dynamic-insert="true" dynamic-update="true" select-before-update="true">
      <cache usage="nonstrict-read-write" />
         <id name="pvtrsid" type="integer">
             <column name="PVTRSID" precision="22" scale="0" />
             <generator class="assigned"></generator>
         </id>
         <version name="version" type="integer">
             <column name="VERSION" precision="22" scale="0" not-null="true" />
         </version>
         <property name="portfoliocusip" type="string">
             <column name="PORTFOLIOCUSIP" length="32" unique="true" />
         </property>
         <property name="trstype" type="string">
             <column name="TRSTYPE" length="64" />
         </property>
         <property name="trsname" type="string">
             <column name="TRSNAME" />
         </property>
         <property name="trsdesc" type="string">
             <column name="TRSDESC" />
         </property>
         <property name="trusteename" type="string">
             <column name="TRUSTEENAME" length="128" />
         </property>
         <property name="manager" type="string">
             <column name="MANAGER" length="128" />
         </property>
         <property name="bankspv" type="string">
             <column name="BANKSPV" length="128" />
         </property>
         <property name="corpspv" type="string">
             <column name="CORPSPV" length="128" />
         </property>
         <property name="minbalancepct" type="double">
             <column name="MINBALANCEPCT" precision="25" scale="6" />
         </property>
         <property name="minbalance" type="double">
             <column name="MINBALANCE" precision="25" scale="6" />
         </property>
         <property name="maxbalance" type="double">
             <column name="MAXBALANCE" precision="25" scale="6" />
         </property>
         <property name="haircut" type="double">
             <column name="HAIRCUT" precision="13" scale="6" />
         </property>
         <property name="fundingspread" type="double">
             <column name="FUNDINGSPREAD" precision="13" scale="6" />
         </property>
         <property name="financespread" type="double">
             <column name="FINANCESPREAD" precision="13" scale="6" />
         </property>
         <property name="hedgeratio" type="double">
             <column name="HEDGERATIO" precision="13" scale="6" />
         </property>
         <property name="startdate" type="date">
             <column name="STARTDATE" length="11" />
         </property>
         <property name="enddate" type="date">
             <column name="ENDDATE" length="11" />
         </property>
         <property name="rampupdate" type="date">
             <column name="RAMPUPDATE" length="11" />
         </property>
         <property name="rampdowndate" type="date">
             <column name="RAMPDOWNDATE" length="11" />
         </property>
         <property name="gkstartdate" type="date">
             <column name="GKSTARTDATE" length="11" />
         </property>
         <property name="gkenddate" type="date">
             <column name="GKENDDATE" length="11" />
         </property>
         <property name="gkfrontstubdate" type="date">
             <column name="GKFRONTSTUBDATE" length="11" />
         </property>
         <property name="gkbackstubdate" type="date">
             <column name="GKBACKSTUBDATE" length="11" />
         </property>
         <property name="paymentfrequency" type="integer">
             <column name="PAYMENTFREQUENCY" precision="22" scale="0" />
         </property>
         <property name="paymentschedule" type="string">
             <column name="PAYMENTSCHEDULE" length="128" />
         </property>
         <property name="trsstatus" type="string">
             <column name="TRSSTATUS" length="32" />
         </property>
         <property name="portfoliotype" type="string">
             <column name="PORTFOLIOTYPE" length="32" />
         </property>
         <property name="liquidationtype" type="string">
             <column name="LIQUIDATIONTYPE" length="32" />
         </property>
         <property name="comments" type="string">
             <column name="COMMENTS" length="255" />
         </property>
         <property name="feepvflag" type="string">
             <column name="FEEPVFLAG" length="1" />
         </property>
         <property name="eodfeepv" type="double">
             <column name="EODFEEPV" precision="25" scale="6" />
         </property>
          <property name="currperiodstartdate" type="date">
             <column name="CURRPERIODSTARTDATE" length="11"  />
         </property>
         <property name="currperiodeffectivestartdate" type="date">
             <column name="CURRPERIODEFFECTIVESTARTDATE" length="11"  />
         </property>
         <property name="recordstatus" type="string">
             <column name="RECORDSTATUS" length="8" not-null="true" />
         </property>
         <property name="createdby" type="string">
             <column name="CREATEDBY" length="32" not-null="true" />
         </property>
         <property name="creationdate" type="timestamp">
             <column name="CREATIONDATE" length="11" not-null="true" />
         </property>
         <property name="modifiedby" type="string">
             <column name="MODIFIEDBY" length="32" not-null="true" />
         </property>
         <property name="modificationdate" type="timestamp">
             <column name="MODIFICATIONDATE" length="11" not-null="true" />
         </property>
         <set name="pvtrslimits" inverse="true"
       cascade="all,delete-orphan" lazy="false" batch-size="10">
       <cache usage="nonstrict-read-write" />
             <key>
                 <column name="PTRSID" precision="22" scale="0" not-null="true" />
             </key>
             <one-to-many class="com.citi.apollo.fmk.model.PtrsLimit" not-found="ignore" />
         </set>
         <set name="pvtrsschedules" inverse="true"
       cascade="all,delete-orphan" lazy="false" batch-size="10">
       <cache usage="nonstrict-read-write" />
             <key>
                 <column name="PVTRSID" precision="22" scale="0" not-null="true" />
             </key>
             <one-to-many class="com.citi.apollo.fmk.model.PvTrsSchedule" not-found="ignore" />
         </set>
         <set name="pvtrsschedulesExt" inverse="true"
       cascade="all,delete-orphan" lazy="false" batch-size="10">
       <cache usage="nonstrict-read-write" />
             <key>
                 <column name="PTRSID" precision="22" scale="0" not-null="true" />
             </key>
             <one-to-many class="com.citi.apollo.fmk.model.PvTrsScheduleExt" not-found="ignore" />
         </set>
         
         <property name="currency" type="string">
             <column name="CURRENCY" length="3" />
         </property>
         <property name="collateralCode" type="string">
             <column name="COLLATERALTYPE" length="1" />
         </property>
         <property name="ratingHierarchyCode" type="string">
             <column name="RATINGTYPE" length="1" />
         </property>
         <property name="variationMarginIndicator" type="string">
             <column name="VARIATIONMARGINFLAG" length="1" />
         </property>                
         <property name="paymentDelay" type="integer">
             <column name="PAYMENTDELAY" precision="8" scale="0" />
         </property>
         <property name="calendarCodes" type="string">
             <column name="CALENDARCODES" length="4000" />
         </property>                
         <property name="ratingAgencyId" type="integer">
             <column name="RATINGAGENCYID" precision="8" scale="0" />
         </property>
         <property name="industry_ratingAgencyId" type="integer">
             <column name="INDUSTRY_RATINGAGENCYID" precision="8" scale="0" />
         </property>
         <property name="allowECOIndustryIndicator" type="string">
             <column name="ALLOWEXCESSCONCINDUSTRY" length="1" />
         </property>                
         <property name="allowECOObligorIndicator" type="string">
             <column name="ALLOWEXCESSCONCOBLIGOR" length="1" />
         </property>
         <property name="masterMnemonic" type="string">
             <column name="MASTERMNEMONIC" length="32" />
         </property>
         <property name="notionalForLimitCalc" type="string">
             <column name="NOTIONALFORLIMITCALC" length="1" />
         </property>
         <property name="paymentStartDate" type="date">
             <column name="PAYMENTSTARTDATE" length="11" />
         </property>
         <property name="actualEndDate" type="date">
             <column name="ACTUALENDDATE" length="11" />
         </property>
         <property name="unsettledIndependentAmtFlag" type="string">
             <column name="UNSETTLEDINDEPENDENTAMTFLAG" length="1" />
         </property>
         <property name="collateralAgreement" type="string">
             <column name="COLLATERAL_AGREEMENT" length="32" />
         </property>
         <property name="strategy" type="string">
             <column name="STRATEGY" length="32" />
         </property>
         <property name="collateralTrigger" type="string">
             <column name="COLLATERAL_TRIGGER" length="1" />
         </property>
  <!--<property name="trsportfoliotypeNumber" type="string">
             <column name="TRSPORTFOLIOTYPE" length="32" />
  </property>-->
         <property name="trsportfoliotype" type="string">
             <column name="TRSPORTFOLIOTYPE" />
         </property>
         <property name="linkedportfolioid" type="integer">
             <column name="LINKEDPORTFOLIOID" precision="8" scale="0" />
         </property>
  <property name="currentNotional"  
      formula="(SELECT SUM(A.NOTIONALAMOUNT) FROM PTRSPOSITION A, PTRSFACILITYATTRIBUTES E WHERE A.PTRSID = PVTRSID AND A.PTRSID = E.PTRSID AND A.LOANFACILITYID = E.LOANFACILITYID AND ROUND(A.COMMITMENTAMOUNT) > 1 )"
      update="false"   insert="false" type="double">
  </property>
  <property name="currentCommitment"  
      formula="(SELECT SUM(A.COMMITMENTAMOUNT) FROM PTRSPOSITION A, PTRSFACILITYATTRIBUTES E WHERE A.PTRSID = PVTRSID AND A.PTRSID = E.PTRSID AND A.LOANFACILITYID = E.LOANFACILITYID AND ROUND(A.COMMITMENTAMOUNT) > 1 )"
      update="false"   insert="false" type="double">
  </property>
  <!--<query name="com.citi.apollo.fmk.persistence.PvTrsTradeDAO.selectShortSeq">
   select PVTRSID from GCD.PVTRS 
  </query>-->
   <property name="annexFileName" type="string">
             <column name="ANNEXFILENAME" />
         </property>
      <property name="tradingStrategy" type="string">
             <column name="TRADINGSTRATEGY" />
         </property>
      </class>
 </hibernate-mapping> 
 
2. query service
SwapTrade exampleTrade = new SwapTrade();
    exampleTrade.setPvtrs(swapTrade.getPvtrs());
    exampleTrade.setLoanfacility(swapTrade.getLoanfacility());   Collection<SwapTrade> trades = null;
   try {
    trades = swapTradeDAO.findByExample(trade);
   } catch (Exception e) {
    log.error("Exception retrieving Trades with Example - "+trade, e);
    throw new ApolloException(e);
   } 
3. hibernate sql
Hibernate: 
     select
         this_.SWAPTRADEID as SWAPTRAD1_26_3_,
         this_.VERSION as VERSION26_3_,
         this_.LOANTRADEID as LOANTRAD3_26_3_,
         this_.LOANFACILITYID as LOANFACI4_26_3_,
         this_.PTRSID as PTRSID26_3_,
         this_.LQTTRADEID as LQTTRADEID26_3_,
         this_.LQTVERSION as LQTVERSION26_3_,
         this_.LQTTICKETID as LQTTICKE8_26_3_,
         this_.TRADESIDE as TRADESIDE26_3_,
         this_.QUANTITY as QUANTITY26_3_,
         this_.TOTALQUANTITY as TOTALQU11_26_3_,
         this_.PRICE as PRICE26_3_,
         this_.LEGALVEHICLE as LEGALVE13_26_3_,
         this_.DESKCD as DESKCD26_3_,
         this_.STRATEGYCD as STRATEGYCD26_3_,
         this_.FIRMACCOUNTCD as FIRMACC16_26_3_,
         this_.COUNTERPARTYCD as COUNTER17_26_3_,
         this_.COUNTERPARTY as COUNTER18_26_3_,
         this_.TRADECCY as TRADECCY26_3_,
         this_.SETTLECCY as SETTLECCY26_3_,
         this_.TRADEDATE as TRADEDATE26_3_,
         this_.SETTLEDATE as SETTLEDATE26_3_,
         this_.FACILITYTERMS as FACILIT23_26_3_,
         this_.OTHERTERMS as OTHERTERMS26_3_,
         this_.COMMENTS as COMMENTS26_3_,
         this_.TRADEACTION as TRADEAC26_26_3_,
         this_.TRADESTATE as TRADESTATE26_3_,
         this_.TRADESTATUS as TRADEST28_26_3_,
         this_.HAIRCUT as HAIRCUT26_3_,
         this_.SWAPSPREAD as SWAPSPREAD26_3_,
         this_.SROFLAG as SROFLAG26_3_,
         this_.PRIMARYTFLAG as PRIMARY32_26_3_,
         this_.USERSPECIFIED as USERSPE33_26_3_,
         this_.RECORDSTATUS as RECORDS34_26_3_,
         this_.CREATEDBY as CREATEDBY26_3_,
         this_.CREATIONDATE as CREATIO36_26_3_,
         this_.MODIFIEDBY as MODIFIEDBY26_3_,
         this_.MODIFICATIONDATE as MODIFIC38_26_3_,
         this_.POSITIONID as POSITIONID26_3_,
         this_.SROBONDFLAG as SROBOND40_26_3_,
         this_.GROUPNUM as GROUPNUM26_3_,
         this_.TRADETYPE as TRADETYPE26_3_,
         this_.GROUPEDTICKETS as GROUPED43_26_3_,
         loanfacili2_.LOANFACILITYID as LOANFACI1_1_0_,
         loanfacili2_.VERSION as VERSION1_0_,
         loanfacili2_.LOANDEALID as LOANDEALID1_0_,
         loanfacili2_.LDRFACILITYID as LDRFACIL4_1_0_,
         loanfacili2_.LDRVERSION as LDRVERSION1_0_,
         loanfacili2_.LDRDEALID as LDRDEALID1_0_,
         loanfacili2_.SNPCUSIP as SNPCUSIP1_0_,
         loanfacili2_.LOANXID as LOANXID1_0_,
         loanfacili2_.LPCID as LPCID1_0_,
         loanfacili2_.MOODYSID as MOODYSID1_0_,
         loanfacili2_.FACILITYCUSIP as FACILIT11_1_0_,
         loanfacili2_.FACILITYTYPE as FACILIT12_1_0_,
         loanfacili2_.FACILITYNAME as FACILIT13_1_0_,
         loanfacili2_.FACILITYDESC as FACILIT14_1_0_,
         loanfacili2_.FACILITYSTATUS as FACILIT15_1_0_,
         loanfacili2_.LSTATYPE as LSTATYPE1_0_,
         loanfacili2_.GLOBALSIZE as GLOBALSIZE1_0_,
         loanfacili2_.ORIGGLOBALSIZE as ORIGGLO18_1_0_,
         loanfacili2_.GLOBALCCY as GLOBALCCY1_0_,
         loanfacili2_.FUNDEDFLAG as FUNDEDFLAG1_0_,
         loanfacili2_.FUNDEDAMOUNT as FUNDEDA21_1_0_,
         loanfacili2_.UNFUNDEDAMOUNT as UNFUNDE22_1_0_,
         loanfacili2_.DRAWDOWNLIMIT as DRAWDOW23_1_0_,
         loanfacili2_.CRAGREEMENTDATE as CRAGREE24_1_0_,
         loanfacili2_.ISSUEDATE as ISSUEDATE1_0_,
         loanfacili2_.MATURITYDATE as MATURIT26_1_0_,
         loanfacili2_.FIXEDRATEFLAG as FIXEDRA27_1_0_,
         loanfacili2_.BASERATECATEGORY as BASERAT28_1_0_,
         loanfacili2_.BASERATE as BASERATE1_0_,
         loanfacili2_.SPREAD as SPREAD1_0_,
         loanfacili2_.ALLINRATE as ALLINRATE1_0_,
         loanfacili2_.LASTRATERESETDATE as LASTRAT32_1_0_,
         loanfacili2_.COUPONFREQUENCY as COUPONF33_1_0_,
         loanfacili2_.RATERESETFREQUENCY as RATERES34_1_0_,
         loanfacili2_.DAYCOUNT as DAYCOUNT1_0_,
         loanfacili2_.REPAYMENTSENIORITY as REPAYME36_1_0_,
         loanfacili2_.SECUREDFLAG as SECURED37_1_0_,
         loanfacili2_.LIENSENIORITY as LIENSEN38_1_0_,
         loanfacili2_.PRORATAFLAG as PRORATA39_1_0_,
         loanfacili2_.MINBORROWAMOUNT as MINBORR40_1_0_,
         loanfacili2_.INCRBORROWAMOUNT as INCRBOR41_1_0_,
         loanfacili2_.PREPAYMENTOPTIONFLAG as PREPAYM42_1_0_,
         loanfacili2_.AMORTIZATIONFLAG as AMORTIZ43_1_0_,
         loanfacili2_.EVERGREENREVOLVERFLAG as EVERGRE44_1_0_,
         loanfacili2_.TERMOUTREVOLVERCONVFLAG as TERMOUT45_1_0_,
         loanfacili2_.TERMOUTREVOLVERCONVDATE as TERMOUT46_1_0_,
         loanfacili2_.PAYMENTINKINDFLAG as PAYMENT47_1_0_,
         loanfacili2_.CITIRATING as CITIRATING1_0_,
         loanfacili2_.SNPRATING as SNPRATING1_0_,
         loanfacili2_.MOODYRATING as MOODYRA50_1_0_,
         loanfacili2_.FITCHRATING as FITCHRA51_1_0_,
         loanfacili2_.DUPLICATECUSIP as DUPLICA52_1_0_,
         loanfacili2_.FUNDEDCUSIP as FUNDEDC53_1_0_,
         loanfacili2_.REVOLVERCOMMCUSIP as REVOLVE54_1_0_,
         loanfacili2_.COMMITEDOBLIGATIONFLAG as COMMITE55_1_0_,
         loanfacili2_.ASSETID as ASSETID1_0_,
         loanfacili2_.COVLITEFLAG as COVLITE57_1_0_,
         loanfacili2_.RECORDSTATUS as RECORDS58_1_0_,
         loanfacili2_.CREATEDBY as CREATEDBY1_0_,
         loanfacili2_.CREATIONDATE as CREATIO60_1_0_,
         loanfacili2_.MODIFIEDBY as MODIFIEDBY1_0_,
         loanfacili2_.MODIFICATIONDATE as MODIFIC62_1_0_,
         loandeal5_.LOANDEALID as LOANDEALID0_1_,
         loandeal5_.VERSION as VERSION0_1_,
         loandeal5_.LDRDEALID as LDRDEALID0_1_,
         loandeal5_.LDRVERSION as LDRVERSION0_1_,
         loandeal5_.DEALSNPCUSIP as DEALSNPC5_0_1_,
         loandeal5_.DEALTYPE as DEALTYPE0_1_,
         loandeal5_.DEALNAME as DEALNAME0_1_,
         loandeal5_.DEALDESC as DEALDESC0_1_,
         loandeal5_.DEALSTATUS as DEALSTATUS0_1_,
         loandeal5_.CRAGREEMENTDATE as CRAGREE10_0_1_,
         loandeal5_.CRAGREEMENTCLSDATE as CRAGREE11_0_1_,
         loandeal5_.CRAGREEMENTEFFDATE as CRAGREE12_0_1_,
         loandeal5_.CRAGREEMENTMATDATE as CRAGREE13_0_1_,
         loandeal5_.GLOBALSIZE as GLOBALSIZE0_1_,
         loandeal5_.GLOBALCCY as GLOBALCCY0_1_,
         loandeal5_.SYNDCOUNTRY as SYNDCOU16_0_1_,
         loandeal5_.REFINANCEFLAG as REFINAN17_0_1_,
         loandeal5_.AMENDFLAG as AMENDFLAG0_1_,
         loandeal5_.RESTATEFLAG as RESTATE19_0_1_,
         loandeal5_.ISSUERCONSENTFLAG as ISSUERC20_0_1_,
         loandeal5_.MINASSIGNMENTAMOUNT as MINASSI21_0_1_,
         loandeal5_.BUSINESSDAYRULE as BUSINES22_0_1_,
         loandeal5_.LDRISSUERID as LDRISSU23_0_1_,
         loandeal5_.ISSUERNAME as ISSUERNAME0_1_,
         loandeal5_.ISSUERSTATUS as ISSUERS25_0_1_,
         loandeal5_.ISSUECOUNTRYCD as ISSUECO26_0_1_,
         loandeal5_.ISSUECCY as ISSUECCY0_1_,
         loandeal5_.CITIRATING as CITIRATING0_1_,
         loandeal5_.SNPRATING as SNPRATING0_1_,
         loandeal5_.MOODYRATING as MOODYRA30_0_1_,
         loandeal5_.FITCHRATING as FITCHRA31_0_1_,
         loandeal5_.COBINDUSTRYCD as COBINDU32_0_1_,
         loandeal5_.COBINDUSTRYNAME as COBINDU33_0_1_,
         loandeal5_.SICINDUSTRYCD as SICINDU34_0_1_,
         loandeal5_.SICINDUSTRYNAME as SICINDU35_0_1_,
         loandeal5_.DUPLICATELDRDEALID as DUPLICA36_0_1_,
         loandeal5_.SNPISSUERRATING as SNPISSU37_0_1_,
         loandeal5_.SNPCORPFAMILYRATING as SNPCORP38_0_1_,
         loandeal5_.MOODYISSUERRATING as MOODYIS39_0_1_,
         loandeal5_.MOODYCORPFAMILYRATING as MOODYCO40_0_1_,
         loandeal5_.FITCHISSUERRATING as FITCHIS41_0_1_,
         loandeal5_.FITCHCORPFAMILYRATING as FITCHCO42_0_1_,
         loandeal5_.RECORDSTATUS as RECORDS43_0_1_,
         loandeal5_.CREATEDBY as CREATEDBY0_1_,
         loandeal5_.CREATIONDATE as CREATIO45_0_1_,
         loandeal5_.MODIFIEDBY as MODIFIEDBY0_1_,
         loandeal5_.MODIFICATIONDATE as MODIFIC47_0_1_,
         pvtrs1_.PVTRSID as PVTRSID10_2_,
         pvtrs1_.VERSION as VERSION10_2_,
         pvtrs1_.PORTFOLIOCUSIP as PORTFOLI3_10_2_,
         pvtrs1_.TRSTYPE as TRSTYPE10_2_,
         pvtrs1_.TRSNAME as TRSNAME10_2_,
         pvtrs1_.TRSDESC as TRSDESC10_2_,
         pvtrs1_.TRUSTEENAME as TRUSTEEN7_10_2_,
         pvtrs1_.MANAGER as MANAGER10_2_,
         pvtrs1_.BANKSPV as BANKSPV10_2_,
         pvtrs1_.CORPSPV as CORPSPV10_2_,
         pvtrs1_.MINBALANCEPCT as MINBALA11_10_2_,
         pvtrs1_.MINBALANCE as MINBALANCE10_2_,
         pvtrs1_.MAXBALANCE as MAXBALANCE10_2_,
         pvtrs1_.HAIRCUT as HAIRCUT10_2_,
         pvtrs1_.FUNDINGSPREAD as FUNDING15_10_2_,
         pvtrs1_.FINANCESPREAD as FINANCE16_10_2_,
         pvtrs1_.HEDGERATIO as HEDGERATIO10_2_,
         pvtrs1_.STARTDATE as STARTDATE10_2_,
         pvtrs1_.ENDDATE as ENDDATE10_2_,
         pvtrs1_.RAMPUPDATE as RAMPUPDATE10_2_,
         pvtrs1_.RAMPDOWNDATE as RAMPDOW21_10_2_,
         pvtrs1_.GKSTARTDATE as GKSTART22_10_2_,
         pvtrs1_.GKENDDATE as GKENDDATE10_2_,
         pvtrs1_.GKFRONTSTUBDATE as GKFRONT24_10_2_,
         pvtrs1_.GKBACKSTUBDATE as GKBACKS25_10_2_,
         pvtrs1_.PAYMENTFREQUENCY as PAYMENT26_10_2_,
         pvtrs1_.PAYMENTSCHEDULE as PAYMENT27_10_2_,
         pvtrs1_.TRSSTATUS as TRSSTATUS10_2_,
         pvtrs1_.PORTFOLIOTYPE as PORTFOL29_10_2_,
         pvtrs1_.LIQUIDATIONTYPE as LIQUIDA30_10_2_,
         pvtrs1_.COMMENTS as COMMENTS10_2_,
         pvtrs1_.FEEPVFLAG as FEEPVFLAG10_2_,
         pvtrs1_.EODFEEPV as EODFEEPV10_2_,
         pvtrs1_.CURRPERIODSTARTDATE as CURRPER34_10_2_,
         pvtrs1_.CURRPERIODEFFECTIVESTARTDATE as CURRPER35_10_2_,
         pvtrs1_.RECORDSTATUS as RECORDS36_10_2_,
         pvtrs1_.CREATEDBY as CREATEDBY10_2_,
         pvtrs1_.CREATIONDATE as CREATIO38_10_2_,
         pvtrs1_.MODIFIEDBY as MODIFIEDBY10_2_,
         pvtrs1_.MODIFICATIONDATE as MODIFIC40_10_2_,
         pvtrs1_.CURRENCY as CURRENCY10_2_,
         pvtrs1_.COLLATERALTYPE as COLLATE42_10_2_,
         pvtrs1_.RATINGTYPE as RATINGTYPE10_2_,
         pvtrs1_.VARIATIONMARGINFLAG as VARIATI44_10_2_,
         pvtrs1_.PAYMENTDELAY as PAYMENT45_10_2_,
         pvtrs1_.CALENDARCODES as CALENDA46_10_2_,
         pvtrs1_.RATINGAGENCYID as RATINGA47_10_2_,
         pvtrs1_.INDUSTRY_RATINGAGENCYID as INDUSTRY48_10_2_,
         pvtrs1_.ALLOWEXCESSCONCINDUSTRY as ALLOWEX49_10_2_,
         pvtrs1_.ALLOWEXCESSCONCOBLIGOR as ALLOWEX50_10_2_,
         pvtrs1_.MASTERMNEMONIC as MASTERM51_10_2_,
         pvtrs1_.NOTIONALFORLIMITCALC as NOTIONA52_10_2_,
         pvtrs1_.PAYMENTSTARTDATE as PAYMENT53_10_2_,
         pvtrs1_.ACTUALENDDATE as ACTUALE54_10_2_,
         pvtrs1_.UNSETTLEDINDEPENDENTAMTFLAG as UNSETTL55_10_2_,
         pvtrs1_.COLLATERAL_AGREEMENT as COLLATERAL56_10_2_,
         pvtrs1_.STRATEGY as STRATEGY10_2_,
         pvtrs1_.COLLATERAL_TRIGGER as COLLATERAL58_10_2_,
         pvtrs1_.TRSPORTFOLIOTYPE as TRSPORT59_10_2_,
         pvtrs1_.LINKEDPORTFOLIOID as LINKEDP60_10_2_,
         pvtrs1_.ANNEXFILENAME as ANNEXFI61_10_2_,
         pvtrs1_.TRADINGSTRATEGY as TRADING62_10_2_,
         (SELECT
             SUM(A.NOTIONALAMOUNT*PKG_ASSET.GETLASTFXRATE(A.TRADECCY,
             E.CURRENCY,
             A.TRADEDATE)) 
         FROM
             PTRSPOSITION A,
             PTRSFACILITYATTRIBUTES E 
         WHERE
             A.PTRSID = pvtrs1_.PVTRSID 
             AND A.PTRSID = E.PTRSID 
             AND A.LOANFACILITYID = E.LOANFACILITYID 
             AND ROUND(A.COMMITMENTAMOUNT) > 1 ) as formula0_2_,
         (SELECT
             SUM(A.COMMITMENTAMOUNT*PKG_ASSET.GETLASTFXRATE(A.TRADECCY,
             E.CURRENCY,
             A.TRADEDATE)) 
         FROM
             PTRSPOSITION A,
             PTRSFACILITYATTRIBUTES E 
         WHERE
             A.PTRSID = pvtrs1_.PVTRSID 
             AND A.PTRSID = E.PTRSID 
             AND A.LOANFACILITYID = E.LOANFACILITYID 
             AND ROUND(A.COMMITMENTAMOUNT) > 1 ) as formula1_2_ 
     from
         GCD.SWAPTRADE this_,
         GCD.LOANFACILITY loanfacili2_,
         GCD.LOANDEAL loandeal5_,
         GCD.PVTRS pvtrs1_ 
     where
         this_.LOANFACILITYID=loanfacili2_.LOANFACILITYID 
         and loanfacili2_.LOANDEALID=loandeal5_.LOANDEALID(+) 
         and this_.PTRSID=pvtrs1_.PVTRSID 
         and (
             1=1
         ) 
         and (
             pvtrs1_.PORTFOLIOCUSIP=? 
             and pvtrs1_.TRSTYPE=? 
             and pvtrs1_.TRSNAME=? 
             and pvtrs1_.TRSDESC=? 
             and pvtrs1_.TRUSTEENAME=? 
             and pvtrs1_.MANAGER=? 
             and pvtrs1_.BANKSPV=? 
             and pvtrs1_.MAXBALANCE=? 
             and pvtrs1_.HEDGERATIO=? 
             and pvtrs1_.STARTDATE=? 
             and pvtrs1_.ENDDATE=? 
             and pvtrs1_.RAMPUPDATE=? 
             and pvtrs1_.RAMPDOWNDATE=? 
             and pvtrs1_.GKSTARTDATE=? 
             and pvtrs1_.GKENDDATE=? 
             and pvtrs1_.GKFRONTSTUBDATE=? 
             and pvtrs1_.GKBACKSTUBDATE=? 
             and pvtrs1_.PAYMENTFREQUENCY=? 
             and pvtrs1_.TRSSTATUS=? 
             and pvtrs1_.PORTFOLIOTYPE=? 
             and pvtrs1_.LIQUIDATIONTYPE=? 
             and pvtrs1_.FEEPVFLAG=? 
             and pvtrs1_.CURRPERIODSTARTDATE=? 
             and pvtrs1_.CURRPERIODEFFECTIVESTARTDATE=? 
             and pvtrs1_.RECORDSTATUS=? 
             and pvtrs1_.CREATEDBY=? 
             and pvtrs1_.CREATIONDATE=? 
             and pvtrs1_.MODIFIEDBY=? 
             and pvtrs1_.MODIFICATIONDATE=? 
             and pvtrs1_.CURRENCY=? 
             and pvtrs1_.COLLATERALTYPE=? 
             and pvtrs1_.RATINGTYPE=? 
             and pvtrs1_.VARIATIONMARGINFLAG=? 
             and pvtrs1_.PAYMENTDELAY=? 
             and pvtrs1_.CALENDARCODES=? 
             and pvtrs1_.RATINGAGENCYID=? 
             and pvtrs1_.INDUSTRY_RATINGAGENCYID=? 
             and pvtrs1_.ALLOWEXCESSCONCINDUSTRY=? 
             and pvtrs1_.ALLOWEXCESSCONCOBLIGOR=? 
             and pvtrs1_.MASTERMNEMONIC=? 
             and pvtrs1_.NOTIONALFORLIMITCALC=? 
             and pvtrs1_.PAYMENTSTARTDATE=? 
             and pvtrs1_.UNSETTLEDINDEPENDENTAMTFLAG=? 
             and pvtrs1_.COLLATERAL_AGREEMENT=? 
             and pvtrs1_.STRATEGY=? 
             and pvtrs1_.COLLATERAL_TRIGGER=? 
             and pvtrs1_.TRSPORTFOLIOTYPE=? 
             and pvtrs1_.LINKEDPORTFOLIOID=? 
             and (
                 SELECT
                     SUM(A.NOTIONALAMOUNT*PKG_ASSET.GETLASTFXRATE(A.TRADECCY,
                     E.CURRENCY,
                     A.TRADEDATE)) 
                 FROM
                     PTRSPOSITION A,
                     PTRSFACILITYATTRIBUTES E 
                 WHERE
                     A.PTRSID = pvtrs1_.PVTRSID 
                     AND A.PTRSID = E.PTRSID 
                     AND A.LOANFACILITYID = E.LOANFACILITYID 
                     AND ROUND(A.COMMITMENTAMOUNT) > 1 
             )=? 
             and (
                 SELECT
                     SUM(A.COMMITMENTAMOUNT*PKG_ASSET.GETLASTFXRATE(A.TRADECCY,
                     E.CURRENCY,
                     A.TRADEDATE)) 
                 FROM
                     PTRSPOSITION A,
                     PTRSFACILITYATTRIBUTES E 
                 WHERE
                     A.PTRSID = pvtrs1_.PVTRSID 
                     AND A.PTRSID = E.PTRSID 
                     AND A.LOANFACILITYID = E.LOANFACILITYID 
                     AND ROUND(A.COMMITMENTAMOUNT) > 1 
             )=? 
             and pvtrs1_.ANNEXFILENAME=? 
             and pvtrs1_.TRADINGSTRATEGY=?
         ) 
         and (
             loanfacili2_.LDRFACILITYID=? 
             and loanfacili2_.LDRDEALID=? 
             and loanfacili2_.SNPCUSIP=? 
             and loanfacili2_.LOANXID=? 
             and loanfacili2_.MOODYSID=? 
             and loanfacili2_.FACILITYCUSIP=? 
             and loanfacili2_.FACILITYTYPE=? 
             and loanfacili2_.FACILITYNAME=? 
             and loanfacili2_.FACILITYDESC=? 
             and loanfacili2_.FACILITYSTATUS=? 
             and loanfacili2_.LSTATYPE=? 
             and loanfacili2_.GLOBALSIZE=? 
             and loanfacili2_.ORIGGLOBALSIZE=? 
             and loanfacili2_.GLOBALCCY=? 
             and loanfacili2_.FUNDEDFLAG=? 
             and loanfacili2_.FUNDEDAMOUNT=? 
             and loanfacili2_.UNFUNDEDAMOUNT=? 
             and loanfacili2_.DRAWDOWNLIMIT=? 
             and loanfacili2_.ISSUEDATE=? 
             and loanfacili2_.MATURITYDATE=? 
             and loanfacili2_.FIXEDRATEFLAG=? 
             and loanfacili2_.BASERATECATEGORY=? 
             and loanfacili2_.BASERATE=? 
             and loanfacili2_.SPREAD=? 
             and loanfacili2_.ALLINRATE=? 
             and loanfacili2_.COUPONFREQUENCY=? 
             and loanfacili2_.RATERESETFREQUENCY=? 
             and loanfacili2_.DAYCOUNT=? 
             and loanfacili2_.REPAYMENTSENIORITY=? 
             and loanfacili2_.SECUREDFLAG=? 
             and loanfacili2_.LIENSENIORITY=? 
             and loanfacili2_.PRORATAFLAG=? 
             and loanfacili2_.MINBORROWAMOUNT=? 
             and loanfacili2_.INCRBORROWAMOUNT=? 
             and loanfacili2_.PREPAYMENTOPTIONFLAG=? 
             and loanfacili2_.AMORTIZATIONFLAG=? 
             and loanfacili2_.EVERGREENREVOLVERFLAG=? 
             and loanfacili2_.TERMOUTREVOLVERCONVFLAG=? 
             and loanfacili2_.PAYMENTINKINDFLAG=? 
             and loanfacili2_.SNPRATING=? 
             and loanfacili2_.MOODYRATING=? 
             and loanfacili2_.COMMITEDOBLIGATIONFLAG=? 
             and loanfacili2_.ASSETID=? 
             and loanfacili2_.COVLITEFLAG=? 
             and loanfacili2_.RECORDSTATUS=? 
             and loanfacili2_.CREATEDBY=? 
             and loanfacili2_.CREATIONDATE=? 
             and loanfacili2_.MODIFIEDBY=? 
             and loanfacili2_.MODIFICATIONDATE=?
         )it will use all the non-id fields of pvtrs and facility as join condition.
 
the best solution is that we create new pvtra ans facility objects, then only set the value of join fields.
SwapTrade exampleTrade = new SwapTrade();
    exampleTrade.setPvtrs(new Pvtrs(pvtrsid));
    exampleTrade.setLoanfacility(new LoanFacility(loanfacilityid));   Collection<SwapTrade> trades = null;
   try {
    trades = swapTradeDAO.findByExample(trade);
   } catch (Exception e) {
    log.error("Exception retrieving Trades with Example - "+trade, e);
    throw new ApolloException(e);
   }