-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL join clause and WITH
PostPosted: Mon Nov 10, 2008 6:11 pm 
Newbie

Joined: Thu Sep 18, 2008 4:32 pm
Posts: 1
I am attempting to use HQL to retrieve a list of objects, but am having difficulty.

I want to get information on all my properties, along with the address and tenant information.
Code:
select house
from Property as house
left join fetch house.Address as address
left join fetch address.tenant as tenant



now I only want to include information for tenants that make more than $50k, so I modify it to this:

Code:
select house
from Property as house
left join fetch house.Address as address
left join fetch address.tenant as tenant
where
tenant.income > 50000

But of course this causes the query to not return the entire property object if there is no tenant associated with the property that has an income greater than 50k.

In SQL I would add a clause to the join against tenant to restrict the set of rows that come from the tenant table rather than a where clause which removes the entire row of data; so trying something similar in HQL I arrive at:
Code:
select house
from Property as house
left join fetch house.Address as address
left join fetch address.tenant as tenant WITH tenant.income > 50000


However this returns the error:
with-clause not allowed on fetched associations; use filters

From the reading I have done it seems that filters are also applied as "WHERE" clauses which seems to indicate that they are not the solution I need.

So -

Am I misunderstanding how filters work and that they can be applied to the join clause?

Is there a way in HQL to achieve the query I want?

Thanks all in advance for any assistance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2008 6:42 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
There are several things called "filters" in Hibernate. The one the error message is referring to is probably the possibility to filter collections as described here:

http://www.hibernate.org/hib_docs/v3/re ... -filtering


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

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.