我有我正在执行的 hql 查询,但收到一个我不太了解原因的错误。
这是我的代码:
@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.CustomEntity.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, Project pro, Leave lr "
+ "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;
}
尝试执行时,我在网页上收到此错误:
org.hibernate.exception.SQLGrammarException:无法提取 ResultSet
还有这个控制台错误:
错误:您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以在第 1 行的“离开 leave2_ where leave2_.Leave_Employee=staff0_.Staff_Code and project1_.Proj”附近使用正确的语法
这似乎表明 where 子句有一些错误,但我没有看到任何特别错误的地方。
更新: 实体类
项目
@Entity
@Table(name="project")
public class Project {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="Project_Code")
public int project_Code;
@Column(name="Project_Customer")
public int project_Customer;
//A lot more attributes...
}
职员
@Entity
@Table(name="staff")
public class Staff
{
@Id
@Column(name="Staff_Code")
public String staff_Code;
...
}
守候你守候我
慕村9548890
慕码人2483693
相关分类