【发布时间】:2021-12-26 14:22:29
【问题描述】:
所以我的存储库中有这段代码(示例):
@Query("SELECT distinct s FROM Model1 ss LEFT JOIN ss.model2 s "
Page<Model2> methodName(long customerId, Pageable pageable);
在 Model1 我有一个字段 LocalDate lastDate。 如果我按 Model2 中的字段排序(使用 Pageable),则代码执行正常 但如果我需要按 model1 字段排序(例如按 lastDate),我会收到错误“无法解析属性”。如果我在“选择”中添加此字段,我也会收到错误“无法转换为 Model2 类”。我能为它做些什么?我不想添加“Order by”子句,也不想将此字段“lastDate”添加到Model1。有没有其他方法可以解决这个问题?
附言 可分页对象使用以下方法签名指定:
public PageRequest(int page, int size, Direction direction, String... properties)
【问题讨论】:
标签: java hibernate jpa spring-data-jpa spring-data