Elias
Elias

Reputation: 694

org.hibernate.QueryException: unexpected char: '`'

I am trying use the following following query using JPARepository but it is throwing

org.hibernate.QueryException: unexpected char: '`' "

exception.

Here is the named query I have:

@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)"
)

Upvotes: 4

Views: 14314

Answers (1)

Elias
Elias

Reputation: 694

atlast I found the solution, I have enabled nativeQuery and return type change to 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();

Upvotes: 7

Related Questions