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!
1 Answer 1
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:
- Spring Data JPA is on the classpath
- 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.
Comments
Explore related questions
See similar questions with these tags.
findByDescription(String description)to have Spring data JPA implement it for you.