From d74decc99a3db99b04dc58d82709f56442f27247 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Tue, 8 Oct 2024 13:12:09 +0200 Subject: [PATCH] Update native query documentation. Closes #3636 Original pull request: #3637 --- .../modules/ROOT/pages/jpa/query-methods.adoc | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/antora/modules/ROOT/pages/jpa/query-methods.adoc b/src/main/antora/modules/ROOT/pages/jpa/query-methods.adoc index 980adac923..6bc1e7c574 100644 --- a/src/main/antora/modules/ROOT/pages/jpa/query-methods.adoc +++ b/src/main/antora/modules/ROOT/pages/jpa/query-methods.adoc @@ -317,6 +317,26 @@ Valid values are (case-insensitive): A similar approach also works with named native queries, by adding the `.count` suffix to a copy of your query. You probably need to register a result set mapping for your count query, though. +Next to obtaining mapped results, native queries allow you to read the raw `Tuple` from the database by choosing a `Map` container as the method's return type. +The resulting map contains key/value pairs representing the actual database column name and the value. + +.Native query retuning raw column name/value pairs +==== +[source, java] +---- +public interface UserRepository extends JpaRepository { + + @NativeQuery("SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?1") + Map findRawMapByEmail(String emailAddress); <1> + + @NativeQuery("SELECT * FROM USERS WHERE LASTNAME = ?1") + List> findRawMapByLastname(String lastname); <2> +} +---- +<1> Single `Map` result backed by a `Tuple`. +<2> Multiple `Map` results backed by ``Tuple``s. +==== + [[jpa.query-methods.sorting]] == Using Sort