-->
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: Partial selection of a one-to-many association
PostPosted: Wed Mar 17, 2004 5:43 am 
Newbie

Joined: Fri Oct 03, 2003 6:53 am
Posts: 7
hi.

i've been using Hibernate 2.1.1 for some months and facing some refactoring in the way the queries are performed in the application.

i have a one-to-many association from User to Purchase (one user can have several purchases). at the very beginning the approach was a lazy initalized set of purchases in the User class, but since a User may have a lot of purchases, and only some of the purchases where really necessary, we had to gave up. now, to get some user's purchases i retrieve the users and for each user i query for the purchases.

Code:
select distinct us
from Purchase as pu
    join pu.user as us
where us.active = 1
and us.userType.userTypeId in (0, 2)
and pu.paid = 1
[... some more constraints ...]
order by us.userId asc


i wonder if it's possible to retrieve the desired purchases (the ones that pass the WHERE clause constraints) as a Set in the User class in a single HQL query.

something like
Code:
select us, pu
would retrieve so many users as purchases he has. so it's not the solution.

maybe there isn't an easy solution for this than to perform it in several steps as we are currently doing.

thnx for any opinion!


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.