0

Got a little problem with custom query in my repository:

@Query("select v from Visit v where YEARWEEK('date') = YEARWEEK(curdate())")

Error shows before YEARWEEK('date') opening bracket:

<expression>, <operator>, AND, GROUP, HAVING, IS, OR or ORDER expected, got '('
2
  • Also SELECT v FROM Visit v looks ambiguous or a typo. Perhaps SELECT v.* FROM Visit v? And the quotes around 'date' would usually represent strings, do you mean backticks `? Commented Jan 31, 2018 at 10:37
  • Spring Data uses JPQL, not SQL (unless you specify it explicitly) - en.wikipedia.org/wiki/Java_Persistence_Query_Language Commented Jan 31, 2018 at 11:09

2 Answers 2

4

you have two options:

For HQL you need following:

@Query("select * from Visit v where YEARWEEK('v.date') = YEARWEEK(curdate())")

You can have native query also, in that case you need following (not the best way for Spring applications, though can be used for some cases)

@Query(value = "select * from Visit where YEARWEEK('date') = YEARWEEK(curdate())", nativeQuery = true)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot :) Solved.
3

The @Query annotation allows to execute native queries by setting the nativeQuery flag to true.

@Query("select v from Visit v where YEARWEEK('date') = YEARWEEK(curdate())", nativeQuery = true)

see spring-data docs Using @Query section.

1 Comment

Thanks a lot :) Solved.

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.