是的,我知道有一些关于此错误的帖子,但是em都没有帮助我。我的hql查询出现此错误:
@SuppressWarnings("unchecked")
@Override
public List<StaffRequest> getStaffLeaveRequest(String userID, Date startDate, Date endDate)
{
Session currentSession = sessionFactory.getCurrentSession();
List<StaffRequest> results =
currentSession.createQuery("select new com.timesheet_Webservice.CustomEnity.StaffRequest(lr.leave_ID, lr.leave_Employee, concat(s.staff_First_Name, ' ', s.staff_Last_Name), "
+ "(lr.leave_Days*8.5), lr.leave_Comments, '1805', concat(pro.project_Pastel_Prefix, ' - ', pro.project_Description), lr.leave_Start, lr.leave_End, lr.leave_IsApproved, "
+ "(select lt.leaveType_Description from LeaveType lt where lt.leaveType_ID = lr.leave_Type)) "
+ "from Staff s, Leave lr, Project pro "
+ "where lr.leave_Employee, = s.staff_Code and pro.project_Code = 1805 and lr.leave_Approved = :userID, and lr.leave_IsApproved = 0 and s.staff_IsEmployee <> 0 "
+ "and lr.leave_Start between :startDate and :endDate "
+ "order by concat(s.staff_First_Name, ' ', s.staff_Last_Name)")
.setParameter("userID",userID).setParameter("startDate", startDate).setParameter("endDate", endDate).getResultList();
return results;
}
我不知道是什么问题。我尝试仔细地重新键入查询,我尝试遵循一些可行的类似查询的格式,但仍然无效。请帮助
更新: 在@Joakim Danielson更正后,完整的错误如下所示:
{"status":400,"message":"org.hibernate.hql.internal.ast.QuerySyntaxException:
unexpected token: , near line 1, column 665 [select new com.timesheet_Webservice.CustomEnity.StaffRequest(lr.leave_ID, lr.leave_Employee, concat(s.staff_First_Name, ' ', s.staff_Last_Name),
(lr.leave_Days*8.5), lr.leave_Comments, '1805', concat(pro.project_Pastel_Prefix, ' - ', pro.project_Description),
lr.leave_Start, lr.leave_End, lr.leave_IsApproved, (select lt.leaveType_Description from com.timesheet_Webservice.entity.LeaveType lt where lt.leaveType_ID = lr.leave_Type)) from com.timesheet_Webservice.entity.Staff s,
com.timesheet_Webservice.entity.Leave lr, com.timesheet_Webservice.entity.Project pro where lr.leave_Employee = s.staff_Code and pro.project_Code = 1805 and lr.leave_Approved = :userID,
and lr.leave_IsApproved = 0 and s.staff_IsEmployee <> 0 and lr.leave_Start between :startDate and :endDate order by concat(s.staff_First_Name, ' ', s.staff_Last_Name)]","timeStamp":1548935385459}
答案 0 :(得分:1)
“其中lr.leave_Employee,= s.staff_Code”,删除逗号
where lr.leave_Employee = s.staff_Code
“ lr.leave_Approved =:userID”中出现第二个逗号错误
lr.leave_Approved = :userID
请注意,在错误消息中,您有unexpected token: , near line 1, column 665
,因此,如果将错误消息中打印的查询粘贴到文本编辑器中,并删除换行符和多余的空格,则会在列(或位置,如果出现错误,您喜欢)665。
不是主题,但我建议您学习在查询中使用JOIN的知识,这样可以大大提高可读性