title: Join Query not working in Hibernate
body: <p>I am executing an <code>inner-join</code> query using <code>hibernate-session.createQuery()</code> and I got the error:</p>
  
  <pre><code>Feb 21, 2014 5:22:07 PM org.hibernate.hql.internal.ast.ErrorCounter reportError
  ERROR: line 1:151: unexpected token: on
  Feb 21, 2014 5:22:07 PM org.hibernate.hql.internal.ast.ErrorCounter reportError
  ERROR: line 1:151: unexpected token: on
  line 1:151: unexpected token: on
      at org.hibernate.hql.internal.antlr.HqlBaseParser.fromJoin(HqlBaseParser.java:1693)
      at org.hibernate.hql.internal.antlr.HqlBaseParser.fromClause(HqlBaseParser.java:1348)
      at org.hibernate.hql.internal.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1054)
      at org.hibernate.hql.internal.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:700)
      at org.hibernate.hql.internal.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:294)
      at org.hibernate.hql.internal.antlr.HqlBaseParser.statement(HqlBaseParser.java:157)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:266)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:180)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:106)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:81)
      at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167)
      at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:217)
      at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:195)
      at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1649)
      at com.sanyasi.masterDataActions.ModifyDistrictsAction.display(ModifyDistrictsAction.java:41)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
      at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
      at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
  </code></pre>
  
  <p>My Query is :</p>
  
  <pre><code>select dist.districtName, dist.status, stat.stateName from sa_district_master dist inner join sa_state_master stat on dist.stateId = stat.stateId
  </code></pre>
  
  <p>But, if I am executing the same Query on my-sql console, it executes perfectly and giving O/P:</p>
  
  <pre><code>+--------------+--------+-----------+
  | districtName | status | stateName |
  +--------------+--------+-----------+
  | Hisar        | 0      | HARYANA   |
  | Gurgaon      | 0      | HARYANA   |
  | Ambala       | 0      | HARYANA   |
  | Rohtak       | 0      | HARYANA   |
  | Sirsa        | 0      | HARYANA   |
  +--------------+--------+-----------+
  </code></pre>
  
  <p>My Hibernate code:</p>
  
  <pre><code>try{
          hibernateSession = HibernateUtil.getSession();
          if(hibernateSession != null){
              Query query = hibernateSession.createQuery("select dist.districtName, dist.status, stat.stateName from sa_district_master dist inner join sa_state_master stat on dist.stateId = stat.stateId");
              List list = query.list();
              for (Object object : list) {
                  Object[] objArray = (Object[])object;
                  System.out.println("Obj : " + objArray[0]);
              }
          }
      } catch (Exception e){
          e.printStackTrace();
      }finally {
          hibernateSession.flush();
          hibernateSession.close();
      }
  </code></pre>
  
  <p>I didn't understand why I'm getting the error...</p>
  
  <p>plzzz help...</p>
  
  <blockquote>
    <p>(Please tell me if anything else you want)</p>
  </blockquote>