Skip to content

Commit fdc85a9

Browse files
committed
Explain custom RowMapper and ResultSetExtractor.
Closes #650
1 parent 0ef725f commit fdc85a9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ 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+
173+
172174
NOTE: Spring fully supports Java 8’s parameter name discovery based on the `-parameters` compiler flag.
173175
By using this flag in your build as an alternative to debug information, you can omit the `@Param` annotation for named parameters.
174176

@@ -198,9 +200,14 @@ The recommended way to do that is a `try-with-resource clause`.
198200
It also means that, once the connection to the database is closed, the stream cannot obtain further elements and likely throws an exception.
199201

200202
[[jdbc.query-methods.at-query.custom-rowmapper]]
201-
=== Custom `RowMapper`
203+
=== Custom `RowMapper` or `ResultSetExtractor`
204+
205+
The `@Query` annotation allows you to specify a custom `RowMapper` or `ResultSetExtractor` to use.
206+
The attributes `rowMapperClass` and `resultSetExtractorClass` allow you to specify classes to use, which will get instantiated using a default constructor.
207+
Alternatively you may set `rowMapperClassRef` or `resultSetExtractorClassRef` to a bean name from your Spring application context.
202208

203-
You can configure which `RowMapper` to use, either by using the `@Query(rowMapperClass = ....)` or by registering a `RowMapperMap` bean and registering a `RowMapper` per method return type.
209+
If you want to use a certain `RowMapper` not just for a single method but for all methods with custom queries returning a certain type,
210+
you may register a `RowMapperMap` bean and registering a `RowMapper` per method return type.
204211
The following example shows how to register `DefaultQueryMappingConfiguration`:
205212

206213
[source,java]

0 commit comments

Comments
 (0)