Using Jparepository and pageable can I make a partial query?

Asked

Viewed 311 times

0

I have an object that is persisted with jparepository, I use paging but it returns all fields which is not necessary for the application. So there is some way to configure a @Query to just pick up 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 pick up the ID and other fields however is not allowing this operation.

1 answer

0

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

In this case it is only returning the fields that I need. As in the example above the ID. This way. I’m leaving to the others that just like I have the same problem what worked for me.

Note that in my case just remove the nativequery as explained the error.

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

However the object does not come as a common java return. it comes as a string arrey. Some solution tip?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.