title: Hibernate Criteria Left Joining Two Tables
body: <p>I have two entities, say Business and Area.</p>
  
  <p>Relevant properties:<br/>
  Business - area, area2, code<br/>
  Area - areaId, areaName</p>
  
  <p>area and area2 of Business map to the id in Area</p>
  
  <p>I'm trying to write a Hibernate criteria that returns all the areas with businesses only.</p>
  
  <p>SQL looks like:
  FROM area a LEFT OUTER JOIN business b on a.areaId = b.area or a.areaId = b.area2
  WHERE b.code != null
  GROUP BY a.areaName</p>
  
  <p>This is what I have:</p>
  
  <pre><code>DetachedCriteria criteria = DetachedCriteria.forClass(Business.class)
  .setProjection(Property.forName("area"))
  .setProjection(Property.forName("area2"))
  .add(Restrictions.ne("code", null));
  
  Criteria criteriaArea = fullTextSession.createCriteria(Area.class)
  .createAlias("areaId", "areaId", CriteriaSpecification.LEFT_JOIN)
  .add(Property.forName("areaId").in(criteria));
  </code></pre>
  
  <p>But this doesn't work, I get a "not an association: areaId" query exception.</p>
  
  <p>Any ideas why this is happening? Thanks.</p>