获取嵌套异常的错误是org.hibernate.hql.ast.QuerySyntaxException:连接所需的路径

时间:2013-03-14 07:17:56

标签: java hibernate

我是hibernate的新手,我有一个查询

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

为什么我收到此错误?

由于

1 个答案:

答案 0 :(得分:0)

您的HQL语法错误。

  1. 您需要使用关键字as指定别名。例如: - Losa_App作为
  2. 如果您提供inner join并完成关联映射,则无需提供on子句。
  3. 如果您想提供a.app_ref_no = os.ref_id,则无需指定inner join。 Hibernate将负责这一点。
  4. 有关详细信息,请查看this question