talk about the MetamodelGenerator in Configuration

since it's used in two places now
This commit is contained in:
Gavin 2023-05-19 20:19:07 +02:00
parent 55d4f0f22c
commit f3ca2d67d5
2 changed files with 22 additions and 9 deletions

View File

@ -84,6 +84,7 @@ Where `{version}` is the latest version of the JDBC driver for your databse.
:validator: https://hibernate.org/validator
:ehcache: https://www.ehcache.org
:infinispan: https://infinispan.org
:generator: https://hibernate.org/orm/tooling/
Optionally, you might also add any of the following additional features:
@ -94,7 +95,7 @@ Optionally, you might also add any of the following additional features:
| An {slf4j}[SLF4J] logging implementation | `org.apache.logging.log4j:log4j-core` or `org.slf4j:slf4j-jdk14`
| A JDBC connection pool, for example, {agroal}[Agroal] | `org.hibernate.orm:hibernate-agroal` and `io.agroal:agroal-pool`
| The Hibernate metamodel generator, if you're using the JPA criteria query API | `org.hibernate.orm:hibernate-jpamodelgen`
| The {generator}[Hibernate Metamodel Generator], especially if you're using the JPA criteria query API | `org.hibernate.orm:hibernate-jpamodelgen`
| {validator}[Hibernate Validator] | `org.hibernate.validator:hibernate-validator` and `org.glassfish:jakarta.el`
| Local second-level cache support via JCache and {ehcache}[EHCache] | `org.hibernate.orm:hibernate-jcache` along with `org.ehcache:ehcache`
| Distributed second-level cache support via {infinispan}[Infinispan] | `org.infinispan:infinispan-hibernate-cache-v60`
@ -104,7 +105,24 @@ Optionally, you might also add any of the following additional features:
|===
You might also add the Hibernate {enhancer}[bytecode enhancer] to your
Gradle build if you want to use field-level lazy fetching.
Gradle build if you want to use <<bytecode-enhancer,field-level lazy fetching>>.
[[metamodel-generator]]
.The Metamodel Generator
****
:generator-guide: {userGuideBase}#tooling-modelgen
Hibernate's {generator}[Metamodel Generator] is an annotation processor that produces what JPA calls a _static metamodel_.
That is, it produces a typed model of the persistent classes in our program, giving us a type-safe way to refer to their attributes in Java code.
In particular, it lets us specify <<entity-graph,entity graphs>> and <<criteria-queries,criteria queries>> in a completely type-safe way.
We've already seen how to set up the annotation processor in the <<hello-hibernate,gradle build>> we saw earlier.
Now, you don't have to use the Metamodel Generator with Hibernate—the APIs we just mentioned also accept plain strings—but we find that it works well with gradle and integrates well with our IDE, and the advantage in typesafety is compelling.
You can find more information in the {generator-guide}[User Guide].
****
[[configuration-jpa]]
=== Configuration using JPA XML

View File

@ -382,8 +382,7 @@ This results in a SQL query with _four_ ``left outer join``s.
[NOTE]
====
In the code examples above, we're making use of the JPA static metamodel.
The classes `Book_` and `Author_` are generated by the annotation processor we have in our <<hello-hibernate,gradle build>>, one of the <<optional-dependencies,optional dependencies>> of Hibernate.
In the code examples above, The classes `Book_` and `Author_` are generated by the <<metamodel-generator,JPA Metamodel Generator>> we saw earlier.
They let us refer to attributes of our model in a completely type-safe way.
We'll use them again, below, when we talk about <<criteria-queries>>.
====
@ -649,11 +648,7 @@ query.select(book).where(where)
.orderBy(cb.asc(book.get(Book_.title)));
----
:generator: https://hibernate.org/orm/tooling/
:generator-guide: {userGuideBase}#tooling-modelgen
Here, the classes `Book_` and `Author_` are classes generated by Hibernate's {generator}[JPA Metamodel Generator], which is documented in the {generator-guide}[User Guide].
They let us refer to attributes of our entities in a typesafe way.
Here, as before, the classes `Book_` and `Author_` are generated by Hibernate's <<metamodel-generator,JPA Metamodel Generator>>.
[CAUTION]
// .Injection attacks and criteria queries