title: Querying "extension tables" using Hibernate
body: <p>I am having a querying issue in Hibernate.  I have a table, 'test', with existing data.  I have a requirement where I can not modify the schema of the test table, so I created another table, 'testExtension', whose primary key is a foreign key to the primary key of Test.  <strong>Data in testExtension is a subset of the data in test. i.e. There will be less rows in 'testExtension' than in 'test'.</strong></p>
  
  <p>I have defined this relationship in a configuration file as follows:</p>
  
  <pre><code>&lt;class name="Test" table="test"&gt;
  &lt;id name="testId" column="test_id"&gt;
      &lt;generator class="sequence"&gt;
          &lt;param name="sequence"&gt;test_id_seq&lt;/param&gt; 
      &lt;/generator&gt;
  &lt;/id&gt;
  
  &lt;property name="name"/&gt;
  
  
  &lt;joined-subclass name="TestExtension" table="testExtension"&gt;
      &lt;key column="test_id"/&gt;
  
      &lt;property name="summary" /&gt;
      &lt;property name="homepage"/&gt;
  &lt;/joined-subclass&gt;
  </code></pre>
  
  <p></p>
  
  <p>With this setup, I am able to create a TestExtension object in my Java program, populate it with data, 'save' it via Hibernate, and commit the transaction.  And it correctly saves data in both Test and TestExtension.  </p>
  
  <p>My problem is occurring when I am trying to query data from these tables.  Right now if I query for a particular test_id using the TestExtension.class to QBE, it will only return a row if that id exists in both Test and TestExtension.  If I use the Test.class to QBE, it will return the row but I will not have access to any of the data stored in TestExtension.</p>
  
  <p>My question is: how can I query these tables so that the results are based off a 'left outer join' of both Test and TestExtension? Any solution is appreciated, whether it's query by example, HQL, or something else (though preferably not raw SQL).</p>
  
  <p>Thanks!</p>