Hi,
a common situation: I have an entities Person and Payment, and I need to show the user a table with all persons and their total payments. In SQL it is SELECT p.*, sum(pay.value) FROM Person p, Payment pay WHERE ... So far, I am aware of several solutions by Hibernate, but I do not know, which one is the best. I need it especially for the criteria query (to be able to sort or filter persons by the total payments.)
Solutions:
1. DV view or @Subselect - I must define more entities for the same table, it might be tedious and cause more coding errors, when some columns are changed. The @MappedSuperclass may help with the coding. But still it is not optimal.
2. @Formula: cons: it is evaluated even when I do not need it.
4. @MappedSuperclass and @Formula: like solution 1., just instead of DB view, one entity has @formula, the other one doesn't.
5. @Transient property and ResultTransformer: cons: tedious coding, refactoring more difficult.
What's the recommended solution for such situation?
Thanks
Andy