title: Hibernate HQL Projection Using Entities ManyToMany Definitions Issue
body: <p><strong>Problem:</strong> HQL query is not returning any results when I reference an entities collection field as part of the HQL statement. It works for one HQL projection for example like this:</p>
  
  <pre class="lang-sql prettyprint-override"><code>select inc.categoryTypes as categoryTypes from IncidentEntity inc where (inc.id = :id105019)
  </code></pre>
  
  <p>The categoryTypes is one of the IncidentEntity classes fields (which is a collection defined as a ManyToMany join as seen below). This works fine, but the issue arises when I am attempting to reference another projection collection that is mapped as a ManyToMany join.</p>
  
  <pre class="lang-sql prettyprint-override"><code>select inc.categoryTypes as categoryTypes, inc.consequences as consequences from IncidentEntity inc where (inc.id = :id105019)
  </code></pre>
  
  <p>As soon as I do it like this, I get an empty set. Which means the SQL query that hibernate generates isn't returning anything. I have verified this by executing the command within SQL Manager which returns no results.</p>
  
  <p>Here is the IncidentEntity:</p>
  
  <pre class="lang-java prettyprint-override"><code>/**
   * Database entity for the 'incidents' table records.&lt;br&gt;
   * Entity domain object is {@link nz.co.doltech.ims.shared.domains.Incident}
   * @author Ben Dol
   * 
   */
  @javax.persistence.Entity(name = "incidents")
  @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
  public class IncidentEntity implements Entity {
  
      ...
  
      @ManyToMany(fetch = FetchType.LAZY)
      @JoinTable(name = "incident_categorytype", joinColumns = { 
              @JoinColumn(name = "incident_id") }, 
          inverseJoinColumns = {
              @JoinColumn(name = "categorytype_id") 
      })
      private Set&lt;CategoryTypeEntity&gt; categoryTypes = new HashSet&lt;CategoryTypeEntity&gt;();
  
      @ManyToMany(fetch = FetchType.LAZY)
      @JoinTable(name = "incident_consequence", joinColumns = { 
              @JoinColumn(name = "incident_id") }, 
          inverseJoinColumns = {
              @JoinColumn(name = "consequence_id") 
      })
      private Set&lt;ConsequenceEntity&gt; consequences = new HashSet&lt;ConsequenceEntity&gt;();
  
      ...
  
      public Set&lt;CategoryTypeEntity&gt; getCategoryTypes() {
          return categoryTypes;
      }
      public void setCategoryTypes(Set&lt;CategoryTypeEntity&gt; categoryTypes) {
          this.categoryTypes = categoryTypes;
      }
  
      public Set&lt;ConsequenceEntity&gt; getConsequences() {
          return consequences;
      }
      public void setConsequences(Set&lt;ConsequenceEntity&gt; consequences) {
          this.consequences = consequences;
      }
  
      ...
  }
  </code></pre>
  
  <p>CategoryTypeEntity relationship definition:</p>
  
  <pre><code>@ManyToMany(fetch = FetchType.LAZY, mappedBy = "categoryTypes")
  private Set&lt;IncidentEntity&gt; incidents = new HashSet&lt;IncidentEntity&gt;();
  </code></pre>
  
  <p>ConsequenceEntity relationship definition:</p>
  
  <pre><code>@ManyToMany(fetch = FetchType.LAZY, mappedBy = "consequences")
  private Set&lt;IncidentEntity&gt; incidents = new HashSet&lt;IncidentEntity&gt;();
  </code></pre>
  
  <p>Data structure:</p>
  
  <p><img src="https://i.stack.imgur.com/Ur7Da.png" alt="relationship-diagram"></p>
  
  <p>Using <strong>Hibernate 3.6.10</strong></p>
  
  <p>Maybe I have setup the definitions wrong, or I am missing a limitation with the HQL here, I'm not sure. Would appreciate any help that I could get here. Thanks!</p>
  
  <p>Regards,
  Ben</p>