Is it possible to use native query + spring data to do pagination?

4

I need to do a paging using dynamic queries because I have to do many joins, I'm trying to make only a select * to test the use of the native query + spring data, but the error message is as follows:

Cannot use native queries with dynamic sorting and/or pagination in method public abstract

Follow the code:

@Query(value = "select i.* " + "from VRS.TB_CLIE_INVS i ",nativeQuery = true)
Page<TbClieInv> testePaginacaoQuery(Pageable pageable);
    
asked by anonymous 10.11.2017 / 16:50

2 answers

1

Try the following:

@Query(value = "SELECT * FROM VRS.TB_CLIE_INVS /*#pageable*/",
       countQuery = "SELECT count(*) FROM VRS.TB_CLIE_INVS",
       nativeQuery = true)
Page<TbClieInv> testePaginacaoQuery(Pageable pageable);

Source: SOen - Spring Data and Native Query with pagination

    
10.11.2017 / 17:08
0

It worked !!!!!

It worked just that way without the order by, the purpose was to simulate PagingAndSorting's page findAll and the test was executed successfully, I had already tried to count as you did, but the key to my problems really was

@Query(value = "SELECT * FROM tabela1 /*#pageable*/",  
       countQuery = "SELECT count(*) FROM tabela1",
       nativeQuery = true)
Page<ClassemodeloTabela> testePaginacaoQuery(Pageable pageable);
    
10.11.2017 / 17:54