0

问题:我想在JPA查询/查询方法级别(使用MariaDb)获取具有提供限制的记录列表。

我正在尝试或尝试过的内容:

我一直在努力摆脱List. POJO我使用 JPA 查询@QueryLIMIT 1但它不接受限制。它给出了编译时错误。所以我试图PageRequest.of(0,1)通过查询来通过限制,但是,仍然不起作用。我还尝试使用 JPA 查询方法findTopByClientIDfindFirstByClientID. 没运气!我得到同样的例外。我不确定我们是否需要在配置中添加一些东西来支持所有这些,但这是RuntimeException.

我得到的例外:

在此处输入图像描述

这是堆栈跟踪中的异常原因。但我没有看到任何SQL语法错误(在运行时创建)。

java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near at line 1

代码:

public interface UserDAO extends JpaRepository<UserPO, Integer>, JpaSpecificationExecutor<UserPO> {
   Page<UserPO> findByClientID(Integer clientID, Pageable pr);
   default Page<UserPO> getFromQueue() {
       return findByClientID(124, PageRequest.of(0, 1));
   }
}

   @Service
   class UserImpl {
 public User getUser() {
    final Page<UserPO> user = userDAO.getFromQueue();
 }  
   }

我不想使用Native Query,使用所以我会失去使用 JPA 的优势。我也在使用MariaDB数据库。让我知道如果您需要更多细节或问题没有很好地构建。

4

0 回答 0