当页面大小小于记录大小 spring 启动时,带分页的本机查询会引发内部服务器错误
Native query with pagination throws internal server error when page size less than record size spring boot
我在 spring 使用分页启动时使用本机查询,问题是当我 运行 页面大小小于记录数的查询时,我得到了一个内部服务器错误,但它工作正常或页面大小大于记录数。下面是我的本机查询
@Query(value = "SELECT * FROM (SELECT * from transactions t where t.book_id=?1 OR t.reflect_book_id=?2 AND t.is_active = true) a inner join " +
"(select id, display_name from customers) b on a.customer_id = b.id order by display_name",
nativeQuery = true)
Page<Transaction> findAllTransactionsByName(String bookId, String reflect_book_id, Pageable pageable);
下面是我遇到的错误
... 110 common frames omitted
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (SELECT *) from transactions t where t.book_id='bid-5778a8af-6bd0-4f3e-87ac' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.18.jar:8.0.18]
我手动打印了 sql 查询和 运行 它并且工作正常。下面是打印在日志上的 sql 查询。
Hibernate: SELECT * FROM (SELECT * from transactions t where t.book_id=? OR t.reflect_book_id=? AND t.is_active = true) a inner join (select id, display_name from customers) b on a.customer_id = b.id order by display_name limit ?
希望您遇到这个问题,需要您在这个问题上的所有专业知识。
谢谢。
- 你能不能通过指定countQuery来试试
@Query(value = "SELECT * FROM (SELECT * from transactions t where t.book_id=?1 OR t.reflect_book_id=?2 AND t.is_active = true) a inner join " +
"(select id, display_name from customers) b on a.customer_id = b.id order by display_name",
countQuery="Your count query goes here",
nativeQuery = true)
Page<Transaction> findAllTransactionsByName(String bookId, String reflect_book_id, Pageable pageable);
我在 spring 使用分页启动时使用本机查询,问题是当我 运行 页面大小小于记录数的查询时,我得到了一个内部服务器错误,但它工作正常或页面大小大于记录数。下面是我的本机查询
@Query(value = "SELECT * FROM (SELECT * from transactions t where t.book_id=?1 OR t.reflect_book_id=?2 AND t.is_active = true) a inner join " +
"(select id, display_name from customers) b on a.customer_id = b.id order by display_name",
nativeQuery = true)
Page<Transaction> findAllTransactionsByName(String bookId, String reflect_book_id, Pageable pageable);
下面是我遇到的错误
... 110 common frames omitted
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (SELECT *) from transactions t where t.book_id='bid-5778a8af-6bd0-4f3e-87ac' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.18.jar:8.0.18]
我手动打印了 sql 查询和 运行 它并且工作正常。下面是打印在日志上的 sql 查询。
Hibernate: SELECT * FROM (SELECT * from transactions t where t.book_id=? OR t.reflect_book_id=? AND t.is_active = true) a inner join (select id, display_name from customers) b on a.customer_id = b.id order by display_name limit ?
希望您遇到这个问题,需要您在这个问题上的所有专业知识。 谢谢。
- 你能不能通过指定countQuery来试试
@Query(value = "SELECT * FROM (SELECT * from transactions t where t.book_id=?1 OR t.reflect_book_id=?2 AND t.is_active = true) a inner join " +
"(select id, display_name from customers) b on a.customer_id = b.id order by display_name",
countQuery="Your count query goes here",
nativeQuery = true)
Page<Transaction> findAllTransactionsByName(String bookId, String reflect_book_id, Pageable pageable);