【发布时间】:2018-11-01 16:41:18
【问题描述】:
我的排序有问题。
存储库方法:
@Query(nativeQuery = true,
value = "SELECT D.ID as dealerId , D.NAME as dealerName, K.ID as kpiId, " +
"K.NAME as kpiName FROM REGION R, DEALER D, KPI K "
+ "WHERE R.IMPORTER_ID = :importerId "
+ "AND D.REGION_ID = R.ID "
+ "AND K.IMPORTER_ID = :importerId ")
Page<DealersKpiTargets> getDealersKpiTargets(@Param("importerId") Long importerId, Pageable pageable);
可分页对象:
Page request [number: 0, size 20, sort: name: DESC]
休眠日志:
Hibernate: SELECT D.ID as dealerId , D.NAME as dealerName, K.ID as kpiId, K.NAME as kpiName FROM REGION R, DEALER D, KPI K WHERE R.IMPORTER_ID = ? AND D.REGION_ID = R.ID AND K.IMPORTER_ID = ? order by R.name desc limit ?
我不明白R.name 前缀来自哪里,在Hibernate 的order by 部分(接近尾声)。
作为参考,我正在使用:
spring-data-jpa 版本 2.0.7.RELEASE
spring-boot-starter-data-jpa 版本 2.0.2.RELEASE
更新
我已经通过将查询从本机查询更改为 jpa 查询解决了这个问题,它正在工作。并且我将笛卡尔坐标改为加入版本。
@Query("SELECT dealerEntity.id AS dealerId , dealerEntity.name AS dealerName, kpiEntity.id AS kpiId, " +
"kpiEntity.name AS kpiName FROM KpiEntity kpiEntity "
+ "JOIN RegionEntity regionEntity ON regionEntity.importerEntity = kpiEntity.importerEntity "
+ "JOIN DealerEntity dealerEntity ON dealerEntity.importerEntity = regionEntity.importerEntity "
+ "WHERE kpiEntity.importerEntity = :importerEntity ")
Page<DealersKpiTargets> getDealersKpiTargets(@Param("importerEntity") ImporterEntity importerEntity, Pageable pageable);
【问题讨论】:
标签: java sorting spring-data-jpa nativequery