I am currently using Hibernate and Spring Jpa Data (mostly for pagination) and I have been having trouble getting this query to work with pagination.
@Query("SELECT NEW com.foo.dto.FooDto (y,(SELECT CASE a.id WHEN NULL THEN 0 ELSE 1 END FROM Banco b LEFT JOIN b.blackList a WHERE b.id = ?1)) FROM Oferta y WHERE y.status = 1")
Page<FooDto> randomSearch(Long idBanco, Pageable pageable);
Error message:
Count query validation failed for method public abstract org.springframework.data.domain.Page
The exactly same query using a List<> as return works fine:
@Query("SELECT NEW com.foo.dto.FooDto(y,(SELECT CASE a.id WHEN NULL THEN 0 ELSE 1 END FROM Banco b LEFT JOIN b.blackList a WHERE b.id = ?1)) FROM Oferta y WHERE y.status = 1")
List<FooDto> randomSearch(Long idBanco, Pageable pageable);
FooDto is simply a class to handle the return.
Obviously my goal here is to paginate Oferta (y alias) resultset. Can someone please enlighten me how to make this work?
The only other way I can think of is splitting the query into 2 different ones and handling the logic on Java itself, but I think it is way more elegant doing it on the database.
Thanks.