現在のアカウント残高オブジェクトには次のプロパティがあります。
long id; // Database ID
Date date; // date when this balance object was created
boolean currentBalanceFlag; // indicates this is the most recent balance
float amount; // the total sum currently in the account balance
float depositAmount; // amount deposited that resulted in this objects amount
float withdrawalAmount; // amount withdrawn that resulted in this objects amount
Balance lastBalance; // last balance object for traversing
User user; // owner of the balance
String note; // detailed description of transaction that resulted in current blanace
天びんに対して実行されるアクションは2つだけです。入出金。
質問は:
次のようなHQLクエリを作成するにはどうすればよいですか?
-sum all
for depositAmount
-sumallfor
-2番目の合計から最初の合計の
結果を減算します-減算の結果を次の値を持つforinオブジェクトと比較しますuser
withdrawalAmount
user
amount
user
Balance
currentBalanceFlag
true
擬似コード:
resultAmount = select ( sum(depositAmount) - sum(withdrawalAmount) ) from Balance where user=user
amount = select amount from Balance where user=user and currentBalanceFlag=true
そして、HQLクエリを使用したデータベースへの単一の呼び出しから取得したい最終的なブール結果:
resultAmount == amount