-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate subquery
PostPosted: Tue Nov 02, 2010 4:07 pm 
Newbie

Joined: Wed Mar 10, 2010 10:14 am
Posts: 12
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.