org.hibernate.QueryException:意外的char:'`'

时间:2018-03-05 04:53:02

标签: java mysql hibernate jpa

我正在尝试使用以下查询使用JPARepository,但它正在抛出

  

org.hibernate.QueryException:意外的char:'`' "

异常。

以下是我的命名查询:

@NamedQuery(name = "shift_planner.fetchThisWeekShiftDetails",
         query = 
         "SELECT r.resouce_name,s.shift_name,sp.plan_date 
          FROM elias.shift_planner sp, elias.resources r, elias.shifts s 
          WHERE sp.resource_id=r.resource_id and sp.shift_id=s.shift_id 
           AND YEARWEEK(`plan_date`, 1) = YEARWEEK(CURDATE(), 1)"
)

1 个答案:

答案 0 :(得分:2)

atlast我找到了解决方案,我启用了nativeQuery并将类型更改返回到Object []。

@Query( value="SELECT resouce_name,shift_name,plan_date FROM   elias.shift_planner sp, elias.resources r, elias.shifts s WHERE  sp.resource_id=r.resource_id and sp.shift_id=s.shift_id and YEARWEEK(`plan_date`, 1) = YEARWEEK(CURDATE(), 1)order by plan_date",nativeQuery = true)
    List<Object[]> fetchThisWeekShiftDetails();