more doc updates for JPA 3.2
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
1fa10e3b53
commit
93c18dafae
|
@ -1226,8 +1226,8 @@ We can place the `@NamedQuery` annotation on any class, even on an entity class.
|
||||||
|
|
||||||
[source,java]
|
[source,java]
|
||||||
----
|
----
|
||||||
@NamedQuery(name="10BooksByTitle",
|
@NamedQuery(name = "10BooksByTitle",
|
||||||
query="from Book where title like :titlePattern order by title fetch first 10 rows only")
|
query = "from Book where title like :titlePattern order by title fetch first 10 rows only")
|
||||||
class BookQueries {}
|
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
|
| Kind | `Session` method | `EntityManager` method | `Query` execution method
|
||||||
|
|
||||||
| Selection | `createNamedSelectionQuery(String,Class)` | `createNamedQuery(String,Class)` | `getResultList()`, `getSingleResult()`, or `getSingleResultOrNull()`
|
| Selection | `createNamedSelectionQuery(String,Class)` | `createNamedQuery(TypedQueryReference)`, `createNamedQuery(String,Class)` | `getResultList()`, `getSingleResult()`, `getSingleResultOrNull()`
|
||||||
| Mutation | `createNamedMutationQuery(String)` | `createNamedQuery(String)` | `executeUpdate()`
|
| Mutation | `createNamedMutationQuery(String)` | `createNamedQuery(TypedQueryReference)`, `createNamedQuery(String)` | `executeUpdate()`
|
||||||
|===
|
|===
|
||||||
|
|
||||||
We execute our named query like this:
|
We execute our named query like this:
|
||||||
|
@ -1265,12 +1265,12 @@ We execute our named query like this:
|
||||||
[source,java]
|
[source,java]
|
||||||
----
|
----
|
||||||
List<Book> books =
|
List<Book> books =
|
||||||
entityManager.createNamedQuery(BookQueries_.QUERY_10_BOOKS_BY_TITLE)
|
entityManager.createQuery(BookQueries_._10BooksByTitle_)
|
||||||
.setParameter("titlePattern", titlePattern)
|
.setParameter("titlePattern", titlePattern)
|
||||||
.getResultList()
|
.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.
|
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.
|
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>>.
|
And queries don't make efficient use of the <<second-level-cache,second level cache>>.
|
||||||
|
|
||||||
We met the <<persistence-operations,`find()`>> method earlier.
|
We met the `find()` and `findMultiple()` methods <<persistence-operations,earlier>>.
|
||||||
It's the most basic way to perform a _lookup_ by id.
|
These are the most basic ways to perform a _lookup_ by id.
|
||||||
But as we also <<entity-graph,already saw>>, it can't quite do everything.
|
But they can't quite do everything.
|
||||||
Therefore, Hibernate has some APIs that streamline certain more complicated lookups:
|
Therefore, Hibernate has some APIs that streamline certain more complicated lookups:
|
||||||
|
|
||||||
.Operations for lookup by id
|
.Operations for lookup by id
|
||||||
|
|
Loading…
Reference in New Issue