Hi All,
I am having a trouble how to work out the query to return just the transaction records that I want to be returned from teh database.
Below is the Hibernate mappings;
Code:
<hibernate-mapping>
<class name="com.connectserver.common.AcctBalance" table="ACCT_BALANCE">
<id name="balanceId" column="BALANCE_ID" type="long" unsaved-value="null">
<generator class="assigned"/>
</id>
<property name="bankMsgId" column="MSG_ID" type="long"/>
<property name="tId" column="T_ID"/>
<property name="acctBSB" column="ACCT_BSB"/>
<property name="acctNumber" column="ACCT_NUMBER" not-null="true"/>
<property name="asOfDate" column="AS_OF_DATE" type="date" not-null="true"/>
<property name="acctName" column="ACCT_NAME"/>
<property name="currencyCode" column="CURRENCY_CODE" not-null="true"/>
<property name="closingBalance" column="CLOSING_BALANCE" type="long"/>
<property name="openingBalance" column="OPENING_BALANCE" type="long"/>
<property name="totalCredits" column="TOTAL_CREDITS" type="long"/>
<property name="numberOfCrTrans" column="NUMBER_OF_CR_TRANS" type="long"/>
<property name="numberOfDrTrans" column="NUMBER_OF_DR_TRANS" type="long"/>
<property name="statusStr" column="STATUS" not-null="true"/>
<set name="transactions" lazy="false" cascade="all" table="ACCT_TRANSACTION">
<key column="BALANCE_ID"/>
<composite-element class="com.connectserver.common.AcctTransaction">
<property name="transactionId" column="TRANSACTION_ID"/>
<property name="tranCode" column="TRAN_CODE"/>
<property name="description" column="DESCRIPTION"/>
<property name="amount" column="AMOUNT" type="long"/>
<property name="refNo" column="REF_NO"/>
<property name="text" column="TEXT"/>
<property name="valueDate" column="VALUE_DATE" type="date"/>
<property name="analysis" column="ANALYSIS"/>
<property name="statusStr" column="STATUS"/>
</composite-element>
</set>
</class>
</hibernate-mapping>
In Java side, transactions is a collection of transaction objects in AcctBalance class.
I want to return all the transaction records that matches with given balance.acctBSB, balance.acctNumber, balance.bankCode and transaction.valueDate
I want to check for valueDate to reduce the number of transactions gets returned from the query.
Below is the query written based on the balance record but I can't figure out how to do that to return transaction records. Below query doesn't help in reducing the size of the data returned becasue it's returning the balance records which in turn contains all the transaction records belong to that balance. But I am only interested in having transaction records that matches with this criteria. Is there any way to do this in Hibernate? Please help.
Quesry based on Balance Records..Code:
queryStr = "FROM AcctBalance.class AS bal join bal.transactions trans WHERE bal.bankCode = ? and bal.acctBSB = ? and bal.acctNumber = ? and trans.valueDate = ? ";
Code:
hbSession.find( queryStr, new Object[] { bank, acctBsb, acctNumber, forThisTran.getValueDate()}, new Type[] {Hibernate.STRING, Hibernate.STRING, Hibernate.STRING, Hibernate.DATE} );