title: How to combine INNER JOIN and LEFT JOIN with JPQL and HQL
body: <p>I'm trying to implement an HQL query.  I've been able to implement it in SQL - which I'm a little more familiar with.  What I keep getting hung up on are the INNER JOINS. </p>
  
  <p>The classes are implemented like this...</p>
  
  <pre><code>class Item
  
  class Component extends Item
      private Item parentItem;
  
  class Assembly extends Item 
  </code></pre>
  
  <p>So far, this is what I have for the HQL...</p>
  
  <pre><code>SELECT
  item.blah,
  comp.blah,
  assembly.blah
  FROM
  Component comp
  LEFT OUTER JOIN comp.parentItem item,
  Assembly assembly
  WHERE 
  item.parentItem = assembly
  </code></pre>
  
  <p>This works - except I need for the last three lines to be a LEFT OUTER JOIN rather than a mutually exclusive condition.  I've tried to implement this in a number of ways - but I keep running into mapping problems.</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class lazy="false" name="com.kcp.common.domain.inventory.Item"
     table="W_INV_INV_ITEM" where="deleted=0"&gt;
  
         &lt;joined-subclass lazy="false" name="com.kcp.common.domain.inventory.Component" table="W_INV_INV_COMPONENT"&gt;
           &lt;key&gt;
             &lt;column name="ID"&gt;
                 &lt;comment&gt;Primary and foreign key to W_INV_INV_ITEM.&lt;/comment&gt;
              &lt;/column&gt;
           &lt;/key&gt;
           &lt;many-to-one cascade="all" class="com.kcp.common.domain.inventory.Item" name="parentItem" outer-join="true"&gt;
                &lt;column name="PARENT_ITEM_ID"&gt;
                  &lt;comment&gt;Foreign key identifying the item to which this component is assembled.&lt;/comment&gt;
                &lt;/column&gt;
           &lt;/many-to-one&gt;
         &lt;/joined-subclass&gt;
  
          &lt;joined-subclass lazy="false" name="com.kcp.common.domain.inventory.Assembly" table="W_INV_INV_MAJOR_ASSEMBLY"&gt;   
            &lt;key&gt;
              &lt;column name="ID"&gt;
                &lt;comment&gt;Primary and foreign key to W_INV_INV_ITEM.&lt;/comment&gt;
              &lt;/column&gt;
            &lt;/key&gt;
      &lt;/class&gt;
   &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Also - I got it to work in SQL like so...</p>
  
  <pre><code>FROM
  DBO.W_INV_INV_ITEM item
  INNER JOIN DBO.W_INV_INV_COMPONENT comp ON item.id = comp.id
  LEFT OUTER JOIN DBO.W_INV_INV_ITEM parentInv ON comp.PARENT_ITEM_ID = parentInv.id
  LEFT OUTER JOIN DBO.W_INV_INV_MAJOR_ASSEMBLY parentMA ON comp.PARENT_ITEM_ID = parentMA.id
  </code></pre>