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!