Skip to content

Commit bc4baf4

Browse files
committed
HHH-19364 improve documentation for Specifications
1 parent 0c3654b commit bc4baf4

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

documentation/src/main/asciidoc/introduction/Interacting.adoc

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,12 +1093,24 @@ We need the following methods of link:{doc-javadoc-url}org/hibernate/query/progr
10931093
| `restrict()` | Add a `Restriction` on the query results
10941094
| `sort()`, `resort()` | Specify how the query results should be ordered
10951095
| `fetch()` | Add a fetched association `Path`
1096-
| `augment()` | Add a custom function which directly manipulates the query
1096+
| `augment()` | Add a custom function which directly manipulates the select query
1097+
|===
1098+
1099+
Two of these operations are also available for a link:{doc-javadoc-url}org/hibernate/query/programmatic/MutationSpecification.html[`MutationSpecification`]:
1100+
1101+
.Methods for mutation restriction
1102+
[%breakable,cols="20,~]
1103+
|===
1104+
| Method name | Purpose
1105+
1106+
| `restrict()` | Add a `Restriction` on the records to be updated
1107+
| `augment()` | Add a custom function which directly manipulates the update or delete query
10971108
|===
10981109

10991110
Alternatively, `Restriction` and `Order` can be used with <<paging-and-ordering,generated query or finder methods>>, and even with link:{doc-data-repositories-url}[Jakarta Data repositories].
11001111

11011112
The interface link:{doc-javadoc-url}org/hibernate/query/restriction/Path.html[`Path`] may be used to express restrictions on fields of an embedded or associated entity class.
1113+
It may even be used for association fetching.
11021114

11031115
[source,java]
11041116
----
@@ -1111,6 +1123,20 @@ List<Book> booksForPublisher =
11111123
.getResultList();
11121124
----
11131125

1126+
Specifications aren't for everything, however.
1127+
1128+
[NOTE]
1129+
====
1130+
`SelectionSpecification` (similar to its friend `MutationSpecification`) may be used in cases where a query returns a single "root" entity, possibly with some fetched associations.
1131+
It's not useful in cases where a query should return multiple entities, a projection of entity fields, or an aggregation.
1132+
For such cases, the full Criteria API is appropriate.
1133+
====
1134+
1135+
Finally, the `augment()` method deserves its own subsection.
1136+
1137+
[[augmentation]]
1138+
=== Augmentation
1139+
11141140
When `Restriction`, `Path`, and `Order` aren't expressive enough, we can _augment_ the query by manipulating its representation as a criteria:
11151141

11161142
[source,java]
@@ -1125,7 +1151,7 @@ var books =
11251151
.getResultList();
11261152
----
11271153

1128-
For really advanced cases, `addAugmentation()` works quite nicely with <<criteria-definition,`CriteriaDefinition`>>.
1154+
For really advanced cases, `augment()` works quite nicely with <<criteria-definition,`CriteriaDefinition`>>.
11291155

11301156
[source,java]
11311157
----
@@ -1144,13 +1170,7 @@ var books =
11441170
----
11451171

11461172
However, we emphasize that this API shines in cases where complex manipulations are _not_ required.
1147-
1148-
[NOTE]
1149-
====
1150-
`SelectionSpecification` (similar to its friend `MutationSpecification`) may be used in cases where a query returns a single "root" entity, possibly with some fetched associations.
1151-
It is not useful in cases where a query should return multiple entities, a projection of entity fields, or an aggregation.
1152-
For such cases, the full Criteria API is appropriate.
1153-
====
1173+
For complicated queries involving multiple entities, or with aggregation and projection, you're best off heading straight to the `CriteriaBuilder`.
11541174

11551175
Programmatic restrictions, and especially programmatic ordering, are often used together with pagination.
11561176

0 commit comments

Comments
 (0)