简体   繁体   中英

Getting QuerySyntaxException: unexpected token

Yes I know there are a few posts of this error, but none of em helped me. I get this error for my hql query:

@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;
}

I can't figure out what the problem is. I tried carefully retyping the query, I tried following the format of some of my similar queries that work, but still nothing. Please help

UPDATE: The full error is as follows after the correction from @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}

"where lr.leave_Employee, = s.staff_Code", remove the comma

where lr.leave_Employee = s.staff_Code

you have a second comma error in "lr.leave_Approved = :userID,"

lr.leave_Approved = :userID

Note that in your error message you have unexpected token: , near line 1, column 665 so if you paste the query printed in the error message into a text editor and remove the line breaks and extra spaces you will find the error in column (or position if you like) 665.

Off topic but may I suggest you learn about using JOIN in your queries, it improves readability a lot

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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