diff --git a/documentation/src/main/asciidoc/introduction/Interacting.adoc b/documentation/src/main/asciidoc/introduction/Interacting.adoc index 63afeebb7b27..bf0f9c35efd9 100644 --- a/documentation/src/main/asciidoc/introduction/Interacting.adoc +++ b/documentation/src/main/asciidoc/introduction/Interacting.adoc @@ -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 {} ---- @@ -1256,8 +1256,8 @@ 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: @@ -1265,12 +1265,12 @@ We execute our named query like this: [source,java] ---- List 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`, 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. @@ -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 <>. -We met the <> method earlier. -It's the most basic way to perform a _lookup_ by id. -But as we also <>, it can't quite do everything. +We met the `find()` and `findMultiple()` methods <>. +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