hibernate 本机sql查询的分页给出:意外标记:开启

dnph8jn4  于 2023-02-13  发布在  其他
关注(0)|答案(1)|浏览(132)

在仓库中编写分页查询时,如下面的代码段所示,我得到了以下错误。
代码

@Repository
public interface Aaaa extends PagingAndSortingRepository<TxnDealerInventoryItem, Long> {

    @Query(value = "SELECT EM.PART_NO, EM.PART_NAME FROM TXN_DEALER_INVENTORY_ITEM E INNER JOIN MST_PRODUCT EM ON E.PRODUCT_ID = EM.PRODUCT_ID WHERE E.ACCOUNT_ID= :accountId AND EM.ALLOW_SERIAL_NUM = :isSerialized ORDER BY ?#{#pageable}",
            countQuery = "SELECT COUNT(*) FROM TXN_DEALER_INVENTORY_ITEM E INNER JOIN MST_PRODUCT EM ON E.PRODUCT_ID = EM.PRODUCT_ID WHERE E.ACCOUNT_ID= :accountId AND EM.ALLOW_SERIAL_NUM = :isSerialized",
            nativeQuery = true)
    Page<Object[]> getNonSerializedDeviceList(@Param("accountId") Long accountId, @Param("isSerialized") String isSerialized, Pageable pageable);
}

错误

HQL: SELECT COUNT(*) FROM TXN_DEALER_INVENTORY_ITEM E INNER JOIN MST_PRODUCT EM ON E.PRODUCT_ID = EM.PRODUCT_ID WHERE E.ACCOUNT_ID= :accountId AND EM.ALLOW_SERIAL_NUM = :isSerialized
2023-02-10 18:52:52,753 ERROR [org.hibernate.hql.internal.ast.ErrorCounter] (http-/127.0.0.1:8881-1) line 1:76: unexpected token: ON

本机查询没有任何错误时,从SQL开发人员运行。
框架版本如下,不幸的是,我不能更新这些任何进一步的限制,在部署环境。您的意见是非常欢迎的!
<spring.version>4.3.30.发布版本</spring.version> <spring.data.version>1.11.23.发布版本</spring.data.version><hibernate.version>4.2.18.最终版本</hibernate.version>
PS:出于测试目的,当我将SQL更改为一个非常基本的选择 * 时,会出现以下错误。

org.hibernate.hql.internal.ast.QuerySyntaxException: TXN_DEALER_INVENTORY_ITEM is not mapped [SELECT COUNT(*) FROM TXN_DEALER_INVENTORY_ITEM E ]
gajydyqb

gajydyqb1#

通过删除计数查询并将返回类型设置为对象数组的列表而不是页面来解决问题,如以下代码段所示。

@Repository
public interface Aaaa extends PagingAndSortingRepository<TxnDealerInventoryItem, Long> {

    @Query(value = "SELECT EM.PART_NO, EM.PART_NAME FROM TXN_DEALER_INVENTORY_ITEM E INNER JOIN MST_PRODUCT EM ON E.PRODUCT_ID = EM.PRODUCT_ID WHERE E.ACCOUNT_ID= :accountId AND EM.ALLOW_SERIAL_NUM = :isSerialized ORDER BY ?#{#pageable}",
            nativeQuery = true)
    List<Object[]> getNonSerializedDeviceList(@Param("accountId") Long accountId, @Param("isSerialized") String isSerialized, Pageable pageable);
}

终于有了很好的老分页:)感谢每一个调查这件事的人。

相关问题