Could not extract result set after using page(pagable) springboot

大憨熊 提交于 2020-12-15 06:30:07

问题


Repository

@Query(value="SELECT * FROM Invoiceupload.invoiceupload where email=:email", nativeQuery=true)

public Page getInvoiceDetailByEmail(String email,Pageable pageable);

Controller

// View all invoices by a vendor

    @GetMapping("/viewByEmail/{email}")
    public Page<Map<String,Object>> getVendorInvoices(@RequestHeader (value="Authorization") String token,@PathVariable("email") String email,Pageable pageable){

        if(request.checkVendorTokenValidity(token)!= null) {    

            return invoiceRepository.getInvoiceDetailByEmail(email, pageable);
        }
        else
            throw new Unauthorized(ErrorMessages.NOT_AUTHORISED);
    }

I am trying to fetch all invoices from db passing email,for now I have 19 invoice records in my db So when i try to run this endpoint from post man it works fine ,returns all 19 invoices BUT when I added another invoice (total=20) it failed to fetch

error:

could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

When I tried replacing Page> with List> it worked fine, so i think there is a problem in page and pageable ,can some one please help


回答1:


To enable pagination for native queries , you needs to declare an additional attribute in your native query. That is countQuery.

 @Query(value="SELECT * FROM Invoiceupload where email=:email", 
  countQuery = "SELECT count(*) FROM Invoiceupload", 
  nativeQuery = true)
Page<Invoiceupload> getInvoiceDetailByEmail(@Param("email")String email,Pageable pageable);


来源:https://stackoverflow.com/questions/58909163/could-not-extract-result-set-after-using-pagepagable-springboot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!