JPA native SQL and Pageable cooperate with error resolution

JPA native SQL and Pageable cooperate with error resolution

I was working on a company project recently, and then used the paging Pageable in JPA to write paging SQL with native SQL, but the result kept reporting an error

Error:

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

SQL code before modification:

@Query(value = "select ds.* from drugstore_seq ds where (:bussType is null or buss_type = :bussType) " +
            "",nativeQuery = true)
Page<DrugstoreSeq> findAllDrugstoreSeq(@Param(value = "bussType") Integer bussType, Pageable pageable);

The reason for this error is that the original SQL and Pageable were written incorrectly. When we write code, we generally require simplification and clear business, so we optimize the SQL.

Modified SQL code:

@Query(value = "select ds from DrugstoreSeq ds where (:bussType is null or ds.bussType = :bussType) " )
Page<DrugstoreSeq> findAllDrugstoreSeq(@Param(value = "bussType") Integer bussType, Pageable pageable);

Code at pageable: PageRequest.of(page - 1, limit, Sort.Direction.DESC, “createDate”)

insert image description here

There is another method I will not explain, because it is too troublesome, if you are interested, you can go to the official website to check
the problem

Guess you like

Origin blog.csdn.net/ITKidKid/article/details/130167244