From fdc85a91ff2da18079e10ee8b9752bc0f2b79939 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Thu, 19 Oct 2023 16:42:15 +0200 Subject: [PATCH] Explain custom RowMapper and ResultSetExtractor. Closes #650 --- .../antora/modules/ROOT/pages/jdbc/query-methods.adoc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/antora/modules/ROOT/pages/jdbc/query-methods.adoc b/src/main/antora/modules/ROOT/pages/jdbc/query-methods.adoc index 30152eabe..6cbe2587e 100644 --- a/src/main/antora/modules/ROOT/pages/jdbc/query-methods.adoc +++ b/src/main/antora/modules/ROOT/pages/jdbc/query-methods.adoc @@ -169,6 +169,8 @@ Properties that don't have a matching column in the result will not be set. 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. Separate queries are generated for maps, lists, sets and arrays of entities. + + NOTE: Spring fully supports Java 8’s parameter name discovery based on the `-parameters` compiler flag. By using this flag in your build as an alternative to debug information, you can omit the `@Param` annotation for named parameters. @@ -198,9 +200,14 @@ The recommended way to do that is a `try-with-resource clause`. It also means that, once the connection to the database is closed, the stream cannot obtain further elements and likely throws an exception. [[jdbc.query-methods.at-query.custom-rowmapper]] -=== Custom `RowMapper` +=== Custom `RowMapper` or `ResultSetExtractor` + +The `@Query` annotation allows you to specify a custom `RowMapper` or `ResultSetExtractor` to use. +The attributes `rowMapperClass` and `resultSetExtractorClass` allow you to specify classes to use, which will get instantiated using a default constructor. +Alternatively you may set `rowMapperClassRef` or `resultSetExtractorClassRef` to a bean name from your Spring application context. -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. +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, +you may register a `RowMapperMap` bean and registering a `RowMapper` per method return type. The following example shows how to register `DefaultQueryMappingConfiguration`: [source,java]