我正在为我的Spring项目构建一个本机查询。有人知道是什么问题吗?
@Query(value = "SELECT e.first_name as firstName, e.last_name as lastName, jh.start_date as startDate, jh.end_date as endDate, " +
"j.job_title as jobName, d.department_name as departmentName FROM JOB_HISTORY jh " +
"JOIN JOBS j ON jh.JOB_ID = j.JOB_ID " +
"JOIN DEPARTMENTS d ON JH.DEPARTMENT_ID = d.DEPARTMENT_ID " +
"JOIN EMPLOYEES e ON jh.EMPLOYEE_ID = e.EMPLOYEE_ID " +
"ORDER BY jh.:sortBy :orderBy")
List<EmployeeJobView> getAllEmployeeJob(String sortBy, String orderBy);在第1行附近,第348列org.hibernate.hql.internal.ast.QuerySyntaxException:选择e.first_name作为firstName,e.last_na me作为lastName,jh.start_date作为startDate,jh.end_date作为endDate,j.job_title作为jobName,d.department_name as departmentName FROM JOB_HISTORY jh jh.JOB_ID jh.JOB_ID= j.JOB_ID联接部门d JH.DEPARTMENT_ID = d.DEPAR TMENT_ID加入雇员e ON jh.EMPLOYEE_ID = e.EMPLOYEE_ID命令jh.:sortBy :orderBy
发布于 2021-03-19 15:21:57
如果我说得对,我会用SPeL重写最后一行:
"ORDER BY jh.?#{[0]} ?#{[1]}"正如Simon Martinelli所提到的,您应该使用nativeQuery = true。
还请参阅SPeL和JPA指南,这里是https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions。
https://stackoverflow.com/questions/66710208
复制相似问题