'Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: users is not mapped [Select username from users]
what is causing the error -> Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: users is not mapped [Select username from users]
. I am trying to validate users when they try to login and it is my first time creating a web API. Is this error caused because I am not properly querying the database's data? Or is my overall syntax not correct?
Here is my UserRepository:
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
@Query("Select username from users")
User findByUsername(@Param("username") String username);
}
and here is my LoginController:
@RestController
@RequestMapping("/users")
public class LoginController {
@Autowired
UserService userService;
@Autowired
ServletRequest servletRequest;
@Autowired
ServletResponse response;
@GetMapping("/signin")
public void login(@RequestBody User user) throws IOException {
User storedUser = userService.getUsername(user.getUsername());
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
if (storedUser == null) {
((HttpServletResponse) response).sendError(HttpServletResponse.SC_UNAUTHORIZED,
"The username or password you have entered is invalid.");
}
else if (storedUser.getPassword() == user.getPassword()) {
((HttpServletResponse) response).sendError(HttpServletResponse.SC_ACCEPTED, "valid.");
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|