java - Hibernate search collection total -


say have resolution arraylist collection of refund objects, integer of amount.

the end result want search on resolutions on sum of refund's amounts, without use of hql.

currently doing summing in mysql clumsy, maintains normalisation , can guarantee correct.

a way thought of doing having refundtotal in resolution, field in database. have private 0 argument setter loops through refund, sums amount , stores when flush happens. setter run on database retrieval, correct when comes out of database. getter ensures correct whenever needed should needed.

private setrefundtotal(){    arraylist<refund> refunds = getrefunds();    integer refundtotalsum = 0;    for(refunds refund refund){       refundtotalsum+=refund.getamount();    }    this.refundtotal = refundtotalsum; }  public integer getrefundtotal(){    this.setrefundtotal();    return totalrefund; } 

if update refund in isolation of resolution however, have , save resolution refundtotal stays consistent.

i'm sure extremely common scenario hibernate has solution for?

you may consider use @formula replace collection of refund, this:

@formula(value = "select sum(t.amount) user_transaction t t.abstractenvelope_id = id") private long total; 

see detail here


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -