-->
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 elements() query with an outer join
PostPosted: Thu Jul 10, 2008 10:25 pm 
Beginner
Beginner

Joined: Sun Apr 09, 2006 9:07 pm
Posts: 24
Hibernate version: 1.2.0

Mapping documents:

<class name="Candidate" table="Candidate">
<id name="Id" column="id" type="Guid">
<generator class="foreign">
<param name="property">Member</param>
</generator>
</id>

<one-to-one name="Member" class="Member" />

<bag name="Industries" table="CandidateIndustry" lazy="true">
<key column="candidateId" />
<many-to-many class="Industry" column="industryId" />
</bag>

... (other stuff) ...


Name and version of the database you are using: MS SQL 2005

The generated SQL (show_sql=true):

select candidate0_.id as x0_0_, industry2_.id as x1_0_ from Candidate candidate0_, CandidateIndustry industries1_, Industry industry2_ where candidate0_.id=industries1_.candidateId and industries1_.industryId=industry2_.id



I have a Candidate classw with a many-to-many mapping to an Industry class. I'd like to run an HQL query that would return the Candidate Id and all the Industries. (I don't want to simply load the class because there are many other properties and joins that I don't need in this case.) So I've tried an HQL query like this:

SELECT c.Id, elements(c.Industries) FROM Candidate c

The problem is that some Candidates have no Industries and they are not returned, because the above SQL has an (effective) inner join. How do I make it do an outer join in this case? I've tried

SELECT c.Id, elements(c.Industries) FROM Candidate c LEFT JOIN c.Industries

and that does the outer join, but it still does the original inner join as well. Then I've tried

SELECT c.Id, elements(c.Industries) FROM Candidate c LEFT JOIN FETCH c.Industries

and that throws an exception. I've also tried changing the mapping above to include fetch="join" outer-join="true" and that seems to have had no effect.


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.