'Query in UserRepository which extends JPA
I've been trying to get a user by username and password from my MySQL database and I keep getting these errors.
@Query("select u from User where u.username = :username and u.password = :password")
public User findByUsernameAndPassword(@Param("username") String username,
@Param("password") String password);
Errors:
Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: Unable to resolve path [u.username], unexpected token [u] [select u from com.Rest.GolfMax.API.Users.User where u.username = :username and u.password = :password]
Caused by: org.hibernate.QueryException: Unable to resolve path [u.username], unexpected token [u]
Solution 1:[1]
a small error in the syntax, I fixed it:
@Query("select u from User u where u.username = :username and u.password = :password")
If you don't encode the password, then this will work for you. But I would recommend using Spring Security for these purposes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Boris Ivanov |
