2013-03-14 52 views
0

我新的休眠和我有一個查詢收到錯誤嵌套的例外是org.hibernate.hql.ast.QuerySyntaxException:路徑預期的加入

select * from Losa_App a 
inner join 
    os_historystep os 
on 
    a.app_ref_no = os.ref_id 
where 
    os.step_name = '011' and app_status = 'R' or app_status = 'S' ; 

當我的SQLDeveloper運行此查詢運行和給我結果。現在我翻譯的查詢到HBL樣

StringBuffer query = new StringBuffer(); 
    List<String> lstObj = new ArrayList<String>(); 
    query.append(" from "); 
    query.append(getClassName()); 
    query.append(" a inner join " 
      // + WflWorkflowHistoryStep.class.getName() 
      + " OS_HISTORYSTEP os with a.appRefNo = os.ref_id " 
      + "where os.step_name = '011' and a.appStatus = 'R' or a.appStatus = 'S' "); 

    List<LosaApp> result = null; 

    try { 

     result = getHibernateTemplate().find(query.toString()); 
     if (CollectionUtils.isNotEmpty(result) { 
      return result; 
     } 

    } catch (Exception e) { 

     String message = e.getMessage(); 
     System.out.println(); 

    } 

    return null; 

但是,當這個查詢運行我得到異常

nested exception is org.hibernate.hql.ast.QuerySyntaxException: Path expected for 
join! [ from com.thetasp.losa.data.LosaApp a inner join OS_HISTORYSTEP os with 
a.appRefNo = os.ref_id where os.step_name = '011' and a.appStatus = 'R' 
or a.appStatus = 'S' ] 

爲什麼我收到這個錯誤?

謝謝

回答

0

您的HQL語法錯誤。

  1. 您需要使用關鍵字as來指定別名。例如: - Losa_App作爲
  2. 如果您給inner join,並且已完成關聯映射,那麼您無需提供on子句。
  3. 如果你想給a.app_ref_no = os.ref_id,那麼你不需要指定inner join。 Hibernate會照顧到這一點。

欲瞭解更多信息,請看看this question

相關問題