title: why is my "left join on" is throwing "unexpected token: on" error?
body: <p>I have two queries to run:</p>
  
  <pre><code>2012-08-07 11:24:02,561 ERROR [org.hibernate.hql.PARSER] (http-0.0.0.0-8080-12) line 1:105: unexpected token: ON
  2012-08-07 11:24:02,686 ERROR [org.jboss.aspects.tx.TxPolicy] (http-0.0.0.0-8080-12) javax.ejb.EJBTransactionRolledbackException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ON near line 1, column 105 
  [SELECT count(o) from ejb.entity.News o LEFT JOIN NewsNewsDistributionServiceLink p ON o.id = p.newsId WHERE o.statusId = ?1 AND p.newsDistServiceCode is ?2]
  
  2012-08-07 11:26:15,605 ERROR [org.hibernate.hql.PARSER] (http-0.0.0.0-8080-12) line 1:105: unexpected token: ON
  2012-08-07 11:26:15,609 ERROR [org.jboss.aspects.tx.TxPolicy] (http-0.0.0.0-8080-12) javax.ejb.EJBTransactionRolledbackException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ON near line 1, column 105 
  [SELECT count(o) from entity.News o LEFT JOIN NewsNewsDistributionServiceLink p ON o.id = p.newsId WHERE o.companyId = ?1 AND o.statusId = ?2 AND p.newsDistServiceCode is ?3]
  </code></pre>
  
  <p>I ran the following in SQuirreL SQL client:</p>
  
  <pre><code>select * from news n left join news_news_distribution_service_link nl
  on n.id=nl.news_id
  where news_distribution_service_code is null
  </code></pre>
  
  <p>This will return results, but when I translate this for my java servlet, it throws that error.</p>
  
  <p>News table:</p>
  
  <pre><code>id -PK
  company_id
  user_id
  title
  type_id
  status_id
  location
  is_immediate
  contents
  created_date
  last_modified_date
  release_date
  delete_date
  corrected_news_id
  can_distribute
  was_distributed
  </code></pre>
  
  <p>NewsNewsDistLink table:</p>
  
  <pre><code>id -PK 
  news_id - this is equal to the id in News
  news_distribution_service_code
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>String _query = "SELECT COUNT(o) FROM News o " + (filter.tierGroup != null ? TIER_GROUP_JOIN : "") + "WHERE ";
              WhereClauseBuilder builder = getWhereClause(filter);
              _query+= builder.where.toString();
  
              Query query = em.createQuery(_query);
              query.setHint("org.hibernate.cacheable", true);
              builder.bind(query);
  </code></pre>
  
  <p>The whereClauseBuilder() basically adds params after "where", the bind() basically binds the param with ?# and its values. Lastly p.newsDistServiceCode will most likely be null most of the time(>95%).</p>