You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/src/main/asciidoc/introduction/Interacting.adoc
+29-9Lines changed: 29 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1093,12 +1093,24 @@ We need the following methods of link:{doc-javadoc-url}org/hibernate/query/progr
1093
1093
| `restrict()` | Add a `Restriction` on the query results
1094
1094
| `sort()`, `resort()` | Specify how the query results should be ordered
1095
1095
| `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
1097
1108
|===
1098
1109
1099
1110
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].
1100
1111
1101
1112
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.
`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
+
1114
1140
When `Restriction`, `Path`, and `Order` aren't expressive enough, we can _augment_ the query by manipulating its representation as a criteria:
1115
1141
1116
1142
[source,java]
@@ -1125,7 +1151,7 @@ var books =
1125
1151
.getResultList();
1126
1152
----
1127
1153
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`>>.
1129
1155
1130
1156
[source,java]
1131
1157
----
@@ -1144,13 +1170,7 @@ var books =
1144
1170
----
1145
1171
1146
1172
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`.
1154
1174
1155
1175
Programmatic restrictions, and especially programmatic ordering, are often used together with pagination.
0 commit comments