short section on named queries

This commit is contained in:
Gavin 2023-05-13 19:14:58 +02:00 committed by Christian Beikov
parent ec2cab572d
commit 1e22d1bb3d
1 changed files with 16 additions and 1 deletions

View File

@ -707,7 +707,22 @@ List<Book> books =
[[named-queries]] [[named-queries]]
=== Named queries === Named queries
TODO The `@NamedQuery` annotation lets us define a HQL query that is compiled and checked as part of the bootstrap process.
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")
class BookQueries {}
----
We have to make sure that the class with the `@NamedQuery` annotation will be scanned by Hibernate, either:
- by adding `<class>org.hibernate.example.BookQueries</class>` to `persistence.xml`, or
- by calling `configuration.addClass(BookQueries.class)`.
The `@NamedNativeQuery` lets us do the same for native SQL queries.
[[jdbc]] [[jdbc]]
=== Interacting directly with JDBC === Interacting directly with JDBC