选择Distinct *作为查询方法? [英] Select Distinct * as query method?

查看:266
本文介绍了选择Distinct *作为查询方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring项目中,我目前仅使用查询方法。

In my Spring project, I'm currently using only query methods.

现在,调用 findAll(Pageable)具有包含某种收集属性的可分页显示页面,我遇到了一个已知的和预期的问题:

Now, when calling findAll(Pageable) with a pageable that contains a sort of a collection property, I'm experiencing a known and expected issue:

DATAJPA-744:按集合属性排序时结果重复

解决这个问题的方法和建议的方法是使用 DISTINCT 关键字过滤结果。

An easy way and also suggested way to solve this is by using the DISTINCT keyword to filter the result.

我的问题是当我创建存储库方法 findDistinct 时,spring在初始化告诉我时抛出了异常

My problem is that when I create the repository method findDistinct, spring throws an exception on initializing telling me


没有找到类型为RoleEntity的属性

No property findDistinct found for type RoleEntity

我的实际代码:

@Repository
public interface RoleRepository extends JpaRepository<RoleEntity, Long>, JpaSpecificationExecutor<RoleEntity>{
    Page<RoleEntity> findDistinct(Specification<RoleEntity> entitySpecification, Pageable pageable);
}

从文档中,我希望它能起作用: SpringDocs:查询方法

From the documentation I would have expected this to work: SpringDocs: query-methods

所以我的问题:

是否可以定义 Select DISTINCT * code>根本没有查询方法?

Is it possible to define a Select DISTINCT * with a query method at all?

推荐答案

根据主键返回的列表已经不同。您必须使用 FindDistinctBy 一些列名。

The List returned is already distinct as per the primary key. You must use FindDistinctBy some column name.

这篇关于选择Distinct *作为查询方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆