Skip to content

Commit 13d4f12

Browse files
committed
Mention usage of SpEL in queries.
Closes #1566
1 parent 09f3cee commit 13d4f12

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/antora/modules/ROOT/pages/jdbc/query-methods.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,18 @@ Properties that don't have a matching column in the result will not be set.
169169
The query is used for populating the aggregate root, embedded entities and one-to-one relationships including arrays of primitive types which get stored and loaded as SQL-array-types.
170170
Separate queries are generated for maps, lists, sets and arrays of entities.
171171

172+
Queries may contain SpEL expressions where bind variables are allowed.
173+
Such a SpEL expression will get replaced with a bind variable and the variable gets bound to the result of the SpEL expression.
172174

175+
.Use a SpEL in a query
176+
[source,java]
177+
----
178+
@Query("SELECT * FROM person WHERE id = :#{person.id}")
179+
Person findWithSpEL(PersonRef person);
180+
----
181+
182+
This can be used to access members of a parameter, as demonstrated in the example above.
183+
For more involved use cases an `EvaluationContextExtension` can be made available in the application context, which in turn can make any object available in to the SpEL.
173184

174185
NOTE: Spring fully supports Java 8’s parameter name discovery based on the `-parameters` compiler flag.
175186
By using this flag in your build as an alternative to debug information, you can omit the `@Param` annotation for named parameters.
@@ -188,6 +199,8 @@ Named queries are expected to be provided in the property file `META-INF/jdbc-na
188199

189200
The location of that file may be changed by setting a value to `@EnableJdbcRepositories.namedQueriesLocation`.
190201

202+
Named queries are handled in the same way as queries provided by annotation.
203+
191204
[[jdbc.query-methods.customizing-query-methods]]
192205
=== Customizing Query Methods
193206

0 commit comments

Comments
 (0)