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: src/main/asciidoc/jpa.adoc
+8
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,7 @@ The JPA module of Spring Data contains a custom namespace that allows defining r
37
37
38
38
Using the `repositories` element looks up Spring Data repositories as described in "`<<repositories.create-instances>>`". Beyond that, it activates persistence exception translation for all beans annotated with `@Repository`, to let exceptions being thrown by the JPA persistence providers be converted into Spring's `DataAccessException` hierarchy.
39
39
40
+
[[jpa.namespace.custom-namespace-attributes]]
40
41
==== Custom Namespace Attributes
41
42
Beyond the default attributes of the `repositories` element, the JPA namespace offers additional attributes to let you gain more detailed control over the setup of the repositories:
42
43
@@ -114,6 +115,7 @@ That means, that repositories will not get instantiated if the client bean is si
114
115
Repository instances will be initialized and verified upon first interaction with the repository.
115
116
* `DEFERRED` -- Fundamentally the same mode of operation as `LAZY`, but triggering repository initialization in response to an `ContextRefreshedEvent` so that repositories are verified before the application has completely started.
116
117
118
+
[[jpa.bootstrap-mode.recommendations]]
117
119
==== Recommendations
118
120
119
121
If you're not using asynchronous JPA bootstrap stick with the default bootstrap mode.
@@ -196,6 +198,7 @@ This means if the arguments actually contain characters recognized by `LIKE` as
196
198
The escape character used can be configured by setting the `escapeCharacter` of the `@EnableJpaRepositories` annotation.
197
199
Compare with <<jpa.query.spel-expressions>>.
198
200
201
+
[[jpa.query-methods.declared-queries]]
199
202
==== Declared Queries
200
203
Although getting a query derived from the method name is quite convenient, one might face the situation in which either the method name parser does not support the keyword one wants to use or the method name would get unnecessarily ugly. So you can either use JPA named queries through a naming convention (see <<jpa.query-methods.named-queries>> for more information) or rather annotate your query method with `@Query` (see <<jpa.query-methods.at-query>> for details).
201
204
@@ -255,6 +258,7 @@ NOTE: `In` and `NotIn` also take any subclass of `Collection` as a parameter as
255
258
256
259
NOTE: The examples use the `<named-query />` element and `@NamedQuery` annotation. The queries for these configuration elements have to be defined in the JPA query language. Of course, you can use `<named-native-query />` or `@NamedNativeQuery` too. These elements let you define the query in native SQL by losing the database platform independence.
To use XML configuration, add the necessary `<named-query />` element to the `orm.xml` JPA configuration file located in the `META-INF` folder of your classpath. Automatic invocation of named queries is enabled by using some defined naming convention. For more details, see below.
260
264
@@ -270,6 +274,7 @@ To use XML configuration, add the necessary `<named-query />` element to the `or
270
274
271
275
The query has a special name that is used to resolve it at runtime.
Annotation-based configuration has the advantage of not needing another configuration file to be edited, lowering maintenance effort. You pay for that benefit by the need to recompile your domain class for every new query declaration.
The query running mechanism for manually defined queries created with `@Query` allows the definition of advanced `LIKE` expressions inside the query definition, as shown in the following example:
In the preceding example, the `LIKE` delimiter character (`%`) is recognized, and the query is transformed into a valid JPQL query (removing the `%`). Upon running the query, the parameter passed to the method call gets augmented with the previously recognized `LIKE` pattern.
346
353
354
+
[[jpa.query-methods.at-query.native]]
347
355
==== Native Queries
348
356
349
357
The `@Query` annotation allows for running native queries by setting the `nativeQuery` flag to true, as shown in the following example:
0 commit comments