-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL left join child problem
PostPosted: Tue Aug 28, 2007 4:05 pm 
Newbie

Joined: Tue Aug 28, 2007 3:35 pm
Posts: 7
Hi,

I have a problem with a report query I'm attempting using HQL.

I have a number of clients, each of which has bought a 0 or more textbooks, each of which belongs to a category. I want a report query that joins the client and textbook records, but only returns rows for a specific category (by name). However, I want my query to include rows for clients who have not bought any textbooks (i.e. left outer join required!).

My HQL query is like this...

select c.name, c.address, t.textbook
from Client c
left join c.textbook t
with t.category.name = 'Java'


I specifically want to limit the results of the left join using the with command.

However, it seems I am not allowed to refer to child objects within the with command - the clause with t.category.name = 'Java' causes Hibernate to throw an exception.

If I change the clause to refer to one of the direct attributes of 't' (e.g. 't.author') there is no problem.

Can you recommend the best approach to filter the results of the join, using a related child object as criteria?


Many thanks,
Chris


Top
 Profile  
 
 Post subject: HQL left join child problem
PostPosted: Wed Aug 29, 2007 4:38 am 
Newbie

Joined: Tue Aug 28, 2007 3:35 pm
Posts: 7
If its any help, the exception hibernate generates is:

org.hibernate.hql.ast.InvalidWithClauseException: with-clause expressions did not reference from-clause element to which the with-clause was associated


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 4:03 pm 
Newbie

Joined: Thu May 31, 2007 3:27 am
Posts: 11
Try this:

Code:
select c.name, c.address, t.textbook
from Client c
left join c.textbook t
join t.category as category with category.name='java'


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.