“default” sort of Paging and Sorting Repository in Spring JPA 是什么?

huangapple go评论74阅读模式
英文:

What is the 'default' sort of Paging and Sorting Repository in Spring JPA?

问题

我正在尝试理解Spring Data JPA分页。

当我调用任何仅带有分页而没有任何排序的findAll时,数据是如何进行排序的。

以下是我尝试从存储库获取第1页(大小为100)的内容。我想知道我得到的结果如何在没有任何隐含排序的情况下进行排序。这种“默认”排序是否取决于从数据库接收到的实际结果顺序。

        Pageable pageRequest = PageRequest.of(1, 100);
        List<Citizen> citizens = citizenRepository.findAll(pageRequest).getContent();
英文:

I'm trying to understand Spring Data JPA paging.

How is the data sorted when I call any findAll with Paging only, without any Sorting.

Below I try to fetch the 1st Page(of size 100) from the repository. I want to know how the result I get is sorted without any implied sorting. Is this 'default' sorting dependent on the actual order of results received from the database.

        Pageable pageRequest = PageRequest.of(1, 100);
        List&lt;Citizen&gt; citizens = citizenRepository.findAll(pageRequest).getContent();

答案1

得分: 0

如果您不传递排序对象,则会应用默认的数据库排序。
对于某些数据库,它是按照主键(ID)进行升序排序,但这不在ANSI规范中,所以我不会依赖于这一点。

英文:

If you don't pass the sort object - then default database sorting is applied.
For some databases it's by primary key (ID) with ASC but this is not in ANSI specification so I wouldn't rely on this.

huangapple
  • 本文由 发表于 2020年4月7日 04:26:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/61068381.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定