how to do native query with pagination?

1

I'm getting a simple select, but I do not know the structure of how to do a select using join. Here is the code below:

This code works:

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

Does not this code work the syntax is wrong?

 @Query(value = "select i.* " + "from tabela1 r 
 /*#pageable*/"
 + "join tabela2 ri on ri.chavetabela2 = 
 r.chavetabela1 "
 + "join tabela3 i on i.chavetabela3 = 
 ri.chavetabela2"
 + "where r.NR_campo1 = ?1 or i.campo2 =?2 ",
 countQuery = "SELECT count(*) FROM tabela1",
 nativeQuery = true)
 public Page<ClasseModeloTabela> testePaginacaoQueryJoin(Long campo1, 
 Long campo2, Pageable pageable);
    
asked by anonymous 13.11.2017 / 18:26

1 answer

0

I already found the answer, for those who have interested the syntax is as follows:

@Query(value = "select i.* " + "from tabela1 r  "
+ "join tabela2 ri on ri.chavetabela2 = r.chavetabela1  "
+ "join tabela3 i on i.chavetabela3 = ri.chavetabela2 "
+ "where r.campo1 = ?1 or i.campo2 =?2 /*#pageable*/ ",
 countQuery = "SELECT count(*) "
+"from tabela1 r  "
+ "join tabela2 ri on ri.chavetabela2 = r.chavetabela1  "
+ "join tabela3 i on i.chavetabela3 = ri.chavetabela2 "
+ "where r.campo1 = ?1 or i.campo2 =?2  ",
   nativeQuery = true)
      public Page<ClasseModeloTabela> testePaginacaoQueryJoin(Long campo1, Long campo2, Pageable pageable);
    
13.11.2017 / 21:09