Trouble implementing Spring Data JPA with custom query for pagination in Java 17
I've been banging my head against this for hours... I'm trying to implement pagination in my Spring Data JPA repository using a custom query, but I'm running into issues with the total count of items returned. I'm using Java 17, Spring Boot 2.6.4, and I have the following repository method: ```java @Repository public interface UserRepository extends JpaRepository<User, Long> { @Query("SELECT u FROM User u WHERE u.status = :status") Page<User> findByStatus(@Param("status") String status, Pageable pageable); } ``` When I call this method in my service layer like this: ```java @Service public class UserService { @Autowired private UserRepository userRepository; public Page<User> getUsersByStatus(String status, int page, int size) { Pageable pageable = PageRequest.of(page, size); return userRepository.findByStatus(status, pageable); } } ``` I expect to get a `Page` object that includes both the users and the total number of users with that status. However, I'm seeing that regardless of the page size, the total count is always returning as 0. I've checked the database and there are definitely users with the specified status. I also tried adding a count query manually, but it didn’t make a difference. Here's the behavior I'm getting when I run the code: ``` Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: u near line 1, column 14 ``` Could this be an scenario with my JPQL syntax, or am I missing something in the Spring Data configuration? Any help would be greatly appreciated! This is part of a larger API I'm building. Thanks in advance!