-->
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: HQL excludes children not matching criteria - as designed?
PostPosted: Sat Jun 04, 2011 5:17 pm 
Newbie

Joined: Sat Jun 04, 2011 4:57 pm
Posts: 1
Hi,

I have the following simple data model.
TableA's relationship to children is 1 to many. The child table has a FK that points back to the PK of TableA, a standard 1:n relationship.

I have an HQL query in the form of

from TableA a
left join fetch a.children ch
where a.attributeA = '<something>'
and ch.attributeB = 'ABC'

The problem is that hibernate will only populate the set of children of the TableA object with only children that match attributeB = 'ABC'.
Whereas I would like to have in the results - if TableA has a child that match the criteria (along with the other TableA criteria) then bring back the TableA row along with *all* the children, not just the ones meeting attributeB = 'ABC'.

Is that possible in HQL? It's not really an outer join.

I know it's possible doing it via 2-pass, but trying to avoid it.

select distinct (a.primaryKey)
from TableA a
left join fetch a.children ch
where a.attributeA = ...
and ch.attributeB = 'ABC'

and then
from TableA where primaryKey in (....)

seems like a kludgy way of doing it.

Thanks in advance,
Giao Nguyen


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.