简体   繁体   English

获取嵌套异常为org.hibernate.hql.ast.QuerySyntaxException的错误:预期加入的路径

[英]getting error that nested exception is org.hibernate.hql.ast.QuerySyntaxException: Path expected for join

I am new to hibernate and I have a query 我是新来的冬眠,我有一个查询

 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' ;

when i run this query on sqldeveloper it runs and give me the results. 当我在sqldeveloper上运行此查询时,它将运行并提供结果。 Now i translated the query into HBL like 现在我将查询翻译成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;

But when this query runs i get exception that 但是当这个查询运行时,我得到了例外

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'  ]

Why i am getting this error ? 为什么我收到此错误?

Thanks 谢谢

Your HQL syntax is wrong. 您的HQL语法错误。

  1. You need to specify the alias by using the keyword as . 您需要使用关键字as来指定别名。 Eg:- Losa_App as a 例如: -Losa_App as a
  2. If you give inner join , and have your association mappings done, then you needn't provide the on clause. 如果您提供了inner join ,并且完成了关联映射,则无需提供on子句。
  3. If you want to give a.app_ref_no = os.ref_id , then you need not specify inner join . 如果要提供a.app_ref_no = os.ref_id ,则无需指定inner join a.app_ref_no = os.ref_id Hibernate will take care of that. 休眠将解决这一问题。

For more info, do have a look at this question . 有关更多信息,请查看此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM