Using Jparepository and pageable can I do a partial query?

0

I have an object that is persisted with jparepository , I use pagination but it returns all fields which is not necessary for the application. So is there any way to set a @Query to just get some data?

@Query(value = "SELECT p.id FROM produto p",
    countQuery = "SELECT p.id FROM produto p",
    nativeQuery = true)
@Override
Page<Produto> findAll(Pageable pageable);

The above example is not working. I just wanted to get the ID and other fields but it is not allowing this to work.

    
asked by anonymous 07.12.2017 / 21:33

1 answer

0

Fortunately while I was studying the documentation more thoroughly, I ended up bumping into solving the problem in a way that was satisfactory to me.

In this case it is only returning the fields that are needed for me. As in the example above the ID. Thus. I'm leaving to others that just as I have the same problem what worked for me.

Note that in my case it was just removing the nativequery as it explained the error.

@Query(value = "SELECT p.id FROM produto p",
        countQuery = "SELECT count(*) FROM produto")
@Override
Page<Produto> findAll(Pageable pageable);

But the object does not come as an ordinary java return. comes as a string arrey. Any solution tips?

    
07.12.2017 / 21:41