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/Processor.adoc
+43-17Lines changed: 43 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,14 @@ The _static metamodel generator_ is a standard part of JPA.
5
5
// It's an annotation processor that produces a statically-typed metamodel of the entity classes in a Java program.
6
6
We've actually already seen its handiwork in the code examples <<main-hibernate,earlier>>: it's the author of the class `Book_`, which contains the static metamodel of the <<book,entity class>> `Book`.
7
7
8
+
Hibernate comes with an annotation processor which does much more than just this.
9
+
It's capable of automatically generating:
10
+
11
+
- <<static-metamodel,JPA metamodel>> classes, as we've already seen,
12
+
- link:{doc-data-repositories-url}#data-static-metamodel[Jakarta Data metamodel] classes,
13
+
- static <<generated-query-methods,query methods>> and <<generated-finder-methods,finder methods>>, and
14
+
- implementations of <<static-or-instance,repository interfaces>>, including link:{doc-data-repositories-url}#repository-interfaces[Jakarta Data repositories].
15
+
8
16
[[metamodel-generator]]
9
17
.Hibernate Processor
10
18
****
@@ -42,6 +50,17 @@ We've already seen how to set up the annotation processor in the <<hello-hiberna
42
50
For more details on how to integrate the Hibernate Processor, check out the {generator-guide}[Static Metamodel Generator] section in the User Guide.
43
51
====
44
52
53
+
[[static-metamodel]]
54
+
=== The static metamodel
55
+
56
+
We've already seen several ways to use the JPA static metamodel.
57
+
Metamodel references are useful for expressing, in a completely type-safe way:
58
+
59
+
- <<criteria-queries,Criteria queries>>,
60
+
- eager fetching via an <<entity-graph,entity graph>>,
61
+
- dynamic <<restrictions-and-ordering,restriction and sorting>>, and
62
+
- references to named <<named-queries,queries>> and named entity graphs.
63
+
45
64
Here's an example of the sort of code that's generated for an entity class, as mandated by the JPA specification:
46
65
47
66
[source,java]
@@ -169,23 +188,10 @@ Actually, Hibernate Processor doesn't require that such annotations be applied t
169
188
We've already been using metamodel references like `Book_.authors` and `Book.AUTHORS` in the previous chapters.
170
189
So now let's see what else Hibernate Processor can do for us.
171
190
172
-
.Hibernate Processor and Jakarta Data
173
-
****
174
-
// For many years we've followed a three-step process: implement, learn from experience, and then standardize.
175
-
//
176
-
The functionality we're about to describe was developed before Jakarta Data took on its current shape, and directly triggered the apocalypse which lead to the final form of the specification.
177
-
Therefore, there's massive overlap between the functionality described in this chapter, and the functionality available via the Jakarta Data annotations.
178
-
On the other hand, Jakarta Data can't do _everything_ described below, and in particular it doesn't yet come with built-in support for stateful persistence contexts or reactive sessions.
179
-
// We are currently working hard to standardize these capabilities, but writing great specifications takes time.
191
+
[[finders-queries-repositories]]
192
+
=== Finder methods, query methods, and repositories
180
193
181
-
We've therefore opted _not_ to rewrite this chapter in a Jakarta Data-centric way, and instead refer you to link:{doc-data-repositories-url}[Introducing Hibernate Data Repositories] for information about the standard Jakarta Data APIs.
182
-
183
-
As Jakarta Data matures, even more of this functionality might be made obsolete, at least in the form described here.
184
-
We're working hard to make this happen.
185
-
****
186
-
187
-
Automatic generation of _finder methods_ and _query methods_ is a relatively new feature of Hibernate Processor, and an extension to the functionality defined by the JPA specification.
188
-
In this chapter, we're going to explore these features.
194
+
Automatic generation of _finder methods_ and _query methods_ is a relatively new feature of Hibernate Processor--originally introduced as an experiment--which ultimately grew into a whole new way to use Hibernate.
189
195
190
196
We're going to meet three different kinds of generated method:
191
197
@@ -198,7 +204,25 @@ We're also going to see two ways that these methods can be called:
198
204
- as static methods of a generated abstract class, or
199
205
- as <<static-or-instance,instance methods of an interface>> with a generated implementation which may even be <<cdi-bean-injection,injected>>.
200
206
201
-
To whet our appetites, let's see how this works for a `@NamedQuery`.
207
+
Back in <<organizing-persistence>>, we walked you through a few different ways to organize your code with the help of Hibernate Processor.
208
+
That journey terminated at the idea of a repository, but we emphasized that you aren't required to stay all the way to the end of the line.
209
+
Repositories are a sweet spot for many users, but they might not be your sweet spot, and that's OK.
210
+
Hibernate Processor is perfectly happy to generate `static` implementations of `@HQL`, `@SQL`, and `@Find` methods, eliminating the need to inject or instantiate a repository object.
211
+
212
+
.Hibernate Processor and Jakarta Data
213
+
****
214
+
// For many years we've followed a three-step process: implement, learn from experience, and then standardize.
215
+
//
216
+
The functionality we're about to describe was developed before Jakarta Data took on its current shape, and directly triggered the apocalypse which lead to the final form of the specification.
217
+
Therefore, there's massive overlap between the functionality described in this chapter, and the functionality available via the Jakarta Data annotations.
218
+
On the other hand, Jakarta Data can't do _everything_ described below, and in particular it doesn't yet come with built-in support for stateful persistence contexts or reactive sessions.
219
+
// We are currently working hard to standardize these capabilities, but writing great specifications takes time.
220
+
221
+
We've therefore opted _not_ to rewrite this chapter in a Jakarta Data-centric way, and instead refer you to link:{doc-data-repositories-url}[Introducing Hibernate Data Repositories] for information about the standard Jakarta Data APIs.
222
+
223
+
As Jakarta Data matures, even more of this functionality might be made obsolete, at least in the form described here.
224
+
We're working hard to make that happen.
225
+
****
202
226
203
227
[CAUTION]
204
228
====
@@ -207,6 +231,8 @@ Hibernate Processor is not currently able to generate finder methods and query m
207
231
(On the other hand, the <<object-relational-mapping,O/R mappings>> may be specified in XML, since they're not needed by the Processor.)
208
232
====
209
233
234
+
To whet our appetites, let's see how it works for a `@NamedQuery`.
0 commit comments