You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/src/main/asciidoc/introduction/Processor.adoc
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,6 +116,56 @@ This is very useful for writing generic code in frameworks or libraries.
116
116
For example, you could use it to create your own criteria query API.
117
117
====
118
118
119
+
The JPA static metamodel for an entity also contains members representing the named queries and named entity graphs declared by `@NamedQuery`, `@NamedNativeQuery`, and `@NamedEntityGraph` annotations of the entity class.
120
+
121
+
For example, if we had:
122
+
123
+
[source,java]
124
+
----
125
+
@CheckHQL // validate named queries at compile time
126
+
@NamedQuery(name="findBooksByTitle",
127
+
query="from Book where title like :title order by title")
Notice that no typecast was required here, since the generated code embeds the return type of the query as a type argument of the JPA `TypedQueryReference`:
144
+
145
+
[source,java]
146
+
----
147
+
/**
148
+
* @see #_findBooksByTitle_
149
+
**/
150
+
public static final String QUERY_FIND_BOOKS_BY_TITLE = "findBooksByTitle";
151
+
152
+
153
+
/**
154
+
* The query named {@value QUERY_FIND_BOOKS_BY_TITLE}
155
+
* <pre>
156
+
* from Book where title like :title order by title
157
+
* </pre>
158
+
*
159
+
* @see org.example.Book
160
+
**/
161
+
public static volatile TypedQueryReference<Book> _findBooksByTitle_;
162
+
----
163
+
164
+
[TIP]
165
+
====
166
+
Actually, Hibernate Processor doesn't require that such annotations be applied to the entity class itself, as we <<organizing-persistence,already saw earlier>>.
167
+
====
168
+
119
169
We've already been using metamodel references like `Book_.authors` and `Book.AUTHORS` in the previous chapters.
120
170
So now let's see what else Hibernate Processor can do for us.
0 commit comments