-->
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: Problem with outer join in hql
PostPosted: Wed Apr 06, 2005 10:28 am 
Newbie

Joined: Tue Mar 01, 2005 3:20 pm
Posts: 6
Hi:

I have one-to-many association between agency and agent entities, agency has a collection of agents.

I am trying to write an hql that would return me only active agencies, each having a collection of only active agents:

Code:
Query q = session.createQuery("from AgencyImpl agency left outer join fetch agency.agents agent where agency.deleted='N' and agent.deleted='N'");


If an agency is active, it should be returned regardless whether it has qualifying agent or not. When run, the above hql returns only those agencies, whose agents meet the criteria "agent.deleted='N'", ignoring outer join clause when agents are missing or when they are inactive.

Please, help.

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 3:48 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Quote:
If an agency is active, it should be returned regardless whether it has qualifying agent or not


If you are outer joining on agent and there are no agents for the agency then by specifying:
Code:
where agency.deleted='N'

in the clause is going to only select those agencies with agents - essentially undoing the work of your outer join.

You need to :
Code:
where (agency.deleted='N' or agency.deleted is null)
to include those without agents


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.