我是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' ]
为什么我收到此错误?
由于
答案 0 :(得分:0)
您的HQL语法错误。
as
指定别名。例如: - Losa_App作为 inner join
并完成关联映射,则无需提供on
子句。a.app_ref_no = os.ref_id
,则无需指定inner join
。 Hibernate将负责这一点。有关详细信息,请查看this question。