| 
					
						 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. 
					
  
						
					 |