Skip to content

Commit 25f78c3

Browse files
committed
add more words and subsections to Hibernate Processor doc chapter
1 parent 6dc2e7b commit 25f78c3

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

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

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ The _static metamodel generator_ is a standard part of JPA.
55
// It's an annotation processor that produces a statically-typed metamodel of the entity classes in a Java program.
66
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`.
77

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+
816
[[metamodel-generator]]
917
.Hibernate Processor
1018
****
@@ -42,6 +50,17 @@ We've already seen how to set up the annotation processor in the <<hello-hiberna
4250
For more details on how to integrate the Hibernate Processor, check out the {generator-guide}[Static Metamodel Generator] section in the User Guide.
4351
====
4452

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+
4564
Here's an example of the sort of code that's generated for an entity class, as mandated by the JPA specification:
4665

4766
[source,java]
@@ -169,23 +188,10 @@ Actually, Hibernate Processor doesn't require that such annotations be applied t
169188
We've already been using metamodel references like `Book_.authors` and `Book.AUTHORS` in the previous chapters.
170189
So now let's see what else Hibernate Processor can do for us.
171190

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
180193

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.
189195

190196
We're going to meet three different kinds of generated method:
191197

@@ -198,7 +204,25 @@ We're also going to see two ways that these methods can be called:
198204
- as static methods of a generated abstract class, or
199205
- as <<static-or-instance,instance methods of an interface>> with a generated implementation which may even be <<cdi-bean-injection,injected>>.
200206

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+
****
202226

203227
[CAUTION]
204228
====
@@ -207,6 +231,8 @@ Hibernate Processor is not currently able to generate finder methods and query m
207231
(On the other hand, the <<object-relational-mapping,O/R mappings>> may be specified in XML, since they're not needed by the Processor.)
208232
====
209233

234+
To whet our appetites, let's see how it works for a `@NamedQuery`.
235+
210236
[[generated-named-queries]]
211237
=== Named queries and Hibernate Processor
212238

0 commit comments

Comments
 (0)