Skip to content

Commit 7b522e6

Browse files
committed
add links and two new admonitions to Pagination chapter
1 parent b58564d commit 7b522e6

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

documentation/src/main/asciidoc/repositories/Pagination.adoc

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ But since Hibernate Data Repositories already validates the content of the `@Ord
6565

6666
Dynamic sorting criteria are expressed using the types `Sort` and `Order`:
6767

68-
- an instance of `Sort` represents a single criterion for sorting query results, and
69-
- an instance of `Order` packages multiple ``Sort``s together.
68+
- an instance of https://jakarta.ee/specifications/data/1.0/apidocs/jakarta.data/jakarta/data/sort[`Sort`] represents a single criterion for sorting query results, and
69+
- an instance of https://jakarta.ee/specifications/data/1.0/apidocs/jakarta.data/jakarta/data/order[`Order`] packages multiple ``Sort``ing criteria together.
7070

7171
A query method may accept an instance of `Sort`.
7272

@@ -107,6 +107,18 @@ var books =
107107

108108
Dynamic sorting criteria may be combined with static criteria.
109109

110+
[TIP]
111+
====
112+
If the entity has entity supertypes, use a lower bounded wildcard in the repository method declaration, for example:
113+
[source,java]
114+
----
115+
@Find
116+
List<Book> books(@Pattern String title, Year yearPublished,
117+
Order<? super Book> order);
118+
----
119+
This lets the caller sort by fields of the supertype.
120+
====
121+
110122
[source,java]
111123
----
112124
@Find
@@ -120,13 +132,13 @@ We're not convinced this is very useful in practice.
120132
[[limits]]
121133
=== Limits
122134

123-
A `Limit` is the simplest way to express a subrange of query results.
135+
A https://jakarta.ee/specifications/data/1.0/apidocs/jakarta.data/jakarta/data/limit[`Limit`] is the simplest way to express a subrange of query results.
124136
It specifies:
125137

126138
- `maxResults`, the maximum number of results to be returned from the database server to the client, and,
127-
- optionally, `startAt`, an offset from the very first result.
139+
- optionally, `startAt`, the position of the first result to be returned to the client.
128140

129-
These values map directly the familiar `setMaxResults()` and `setFirstResults()` of the Jakarta Persistence `Query` interface.
141+
These values map directly to the familiar `setMaxResults()` and `setFirstResult()` of the Jakarta Persistence `Query` interface.
130142

131143
[source,java]
132144
----
@@ -142,12 +154,15 @@ var books =
142154
Limit.of(MAX_RESULTS));
143155
----
144156

157+
[CAUTION]
158+
Whereas `Query.setFirstResult()` is an _offset_ of the first result to be returned, with `setFirstResult(0)` meaning "no offset", `Limit.startAt` numbers results from one, with `Limit.range(1, n)` meaning "at most _n_ results, starting from the first result".
159+
145160
A more sophisticated approach is provided by `PageRequest`.
146161

147162
[[offset-based-pagination]]
148163
=== Offset-based pagination
149164

150-
A `PageRequest` is superficially similar to a `Limit`, except that it's specified in terms of:
165+
A https://jakarta.ee/specifications/data/1.0/apidocs/jakarta.data/jakarta/data/page/pagerequest[`PageRequest`] is superficially similar to a `Limit`, except that it's specified in terms of:
151166

152167
- a page `size`, and
153168
- a numbered `page`.
@@ -176,7 +191,7 @@ The easiest way to be sure that you have a well-defined total order is to specif
176191
For this reason, we specified `@OrderBy("isbn")` in the previous example.
177192
====
178193

179-
However, a repository method which accepts a `PageRequest` may return a `Page` instead of a `List`, making it easier to implement pagination.
194+
However, a repository method which accepts a `PageRequest` may return a https://jakarta.ee/specifications/data/1.0/apidocs/jakarta.data/jakarta/data/page/page[`Page`] of results instead of a `List`, making it easier to implement pagination.
180195

181196
[source,java]
182197
----
@@ -238,7 +253,7 @@ For key-based pagination, it's _essential_ that the query has a total order.
238253
====
239254

240255
From our point of view as users of Jakarta Data, key-based pagination works almost exactly like offset-based pagination.
241-
The difference is that we must declare our repository method to return `CursoredPage`.
256+
The difference is that we must declare our repository method to return https://jakarta.ee/specifications/data/1.0/apidocs/jakarta.data/jakarta/data/page/cursoredpage[`CursoredPage`].
242257

243258
[source,java]
244259
----

0 commit comments

Comments
 (0)