Skip to content

Commit

Permalink
more doc updates for JPA 3.2
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin King <[email protected]>
  • Loading branch information
gavinking committed Oct 23, 2024
1 parent 1fa10e3 commit 93c18da
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions documentation/src/main/asciidoc/introduction/Interacting.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1226,8 +1226,8 @@ We can place the `@NamedQuery` annotation on any class, even on an entity class.

[source,java]
----
@NamedQuery(name="10BooksByTitle",
query="from Book where title like :titlePattern order by title fetch first 10 rows only")
@NamedQuery(name = "10BooksByTitle",
query = "from Book where title like :titlePattern order by title fetch first 10 rows only")
class BookQueries {}
----

Expand Down Expand Up @@ -1256,21 +1256,21 @@ There's much less advantage to using `@NamedNativeQuery`, because there is very
|===
| Kind | `Session` method | `EntityManager` method | `Query` execution method

| Selection | `createNamedSelectionQuery(String,Class)` | `createNamedQuery(String,Class)` | `getResultList()`, `getSingleResult()`, or `getSingleResultOrNull()`
| Mutation | `createNamedMutationQuery(String)` | `createNamedQuery(String)` | `executeUpdate()`
| Selection | `createNamedSelectionQuery(String,Class)` | `createNamedQuery(TypedQueryReference)`, `createNamedQuery(String,Class)` | `getResultList()`, `getSingleResult()`, `getSingleResultOrNull()`
| Mutation | `createNamedMutationQuery(String)` | `createNamedQuery(TypedQueryReference)`, `createNamedQuery(String)` | `executeUpdate()`
|===

We execute our named query like this:

[source,java]
----
List<Book> books =
entityManager.createNamedQuery(BookQueries_.QUERY_10_BOOKS_BY_TITLE)
entityManager.createQuery(BookQueries_._10BooksByTitle_)
.setParameter("titlePattern", titlePattern)
.getResultList()
----

Here, `BookQueries_.QUERY_10_BOOKS_BY_TITLE` is a constant with value `"10BooksByTitle"`, generated by the Hibernate Processor.
Here, `BookQueries_.\_10BooksByTitle_` is an element of the JPA static metamodel of type `TypedQueryReference<Book>`, generated by Hibernate Processor.

Note that the code which executes the named query is not aware of whether the query was written in HQL or in native SQL, making it slightly easier to change and optimize the query later.

Expand All @@ -1293,9 +1293,9 @@ We can do almost anything via HQL, criteria, or native SQL queries.
But when we already know the identifier of the entity we need, a query can feel like overkill.
And queries don't make efficient use of the <<second-level-cache,second level cache>>.

We met the <<persistence-operations,`find()`>> method earlier.
It's the most basic way to perform a _lookup_ by id.
But as we also <<entity-graph,already saw>>, it can't quite do everything.
We met the `find()` and `findMultiple()` methods <<persistence-operations,earlier>>.
These are the most basic ways to perform a _lookup_ by id.
But they can't quite do everything.
Therefore, Hibernate has some APIs that streamline certain more complicated lookups:

.Operations for lookup by id
Expand Down

0 comments on commit 93c18da

Please sign in to comment.