0

I'd like to add a method that finds a Todo item based on a given description. Online people are saying you can use JSQL and that Spring will automatically implement it. I tried the following:

public interface TodoRepo extends CrudRepository<Todo, Long> {
@Query("SELECT t FROM Todo t WHERE t.description=:description")
Todo findByDescription(@Param("description") String description);
}

However, I got an error saying that the symbol "@Query" could not be found. Is there some wiring or importing I'm failing to do? Is there another way to implement a custom method? Thanks!

asked Jun 10, 2018 at 17:41
3
  • Make sure you have import org.springframework.data.jpa.repository.Query; Commented Jun 10, 2018 at 17:54
  • Just read this guide: spring.io/guides/gs/accessing-data-jpa Commented Jun 10, 2018 at 18:24
  • Apart from any dependency problems that you’re obviously having. It is sufficient to just write an unannotated method findByDescription(String description) to have Spring data JPA implement it for you. Commented Jun 11, 2018 at 14:13

1 Answer 1

2

Something is wrong with your dependencies and or imports.

The @Query annotation is part of Spring Data JPA, which you intend to use.

There are two things you have to verify:

  1. Spring Data JPA is on the classpath
  2. You are importing org.springframework.data.jpa.repository.Query

If you update your question with your Maven configuration or comparable and/or a more complete java file including the imports we might give more detailed advice.

answered Jun 11, 2018 at 7:34
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.