0

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}
2
  • what is the exact error and where in the query does it point to? Commented Jan 31, 2019 at 10:50
  • added the full error. How does one trace the line 1 column thing to where it points? Commented Jan 31, 2019 at 11:56

1 Answer 1

1

"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

Sign up to request clarification or add additional context in comments.

2 Comments

Really thought this would be the end of my troubles, but still get the error. Saves me a fix for later though thanks. I will look into it
@DeanStrydom, another comma to much found

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.