Search code examples
sqlspringjpanative

I am facing an error in Spring Boot JPA when using custom native select query


I have created a custom query in my Repository Interface as:

@Query(name = "select * from tblusers where first_name like %?1% OR last_name like %?2% OR username like %?3%", nativeQuery = true)
public List<Optional<UsersEntity>> customizedFindUser(String first_name,String last_name,String username);

And when I try to compile the project am facing the error as:

Could not create query for public abstract java.util.List com.beezy.asserttracker.users.UsersRepository.customizedFindUser(java.lang.String,java.lang.String,java.lang.String); Reason: Failed to create query for method public abstract java.util.List com.beezy.asserttracker.users.UsersRepository.customizedFindUser(java.lang.String,java.lang.String,java.lang.String); No property 'customizedFindUser' found for type 'UsersEntity'

So am confused as to what I have done wrong.

I have tried changing the placeholder numbering as:

@Query(name = "select * from tblusers where first_name like %?%1 OR last_name like %?%2 OR username like %?%3", nativeQuery = true)
    public List<Optional<UsersEntity>> customizedFindUser(String first_name,String last_name,String username);

And then I have also commented out the code and it the project could compile successfully. So I can't figure out what is wrong here.


Solution

  • Property name of @Query anotation related to named queries. Use value instead