Skip to content

Commit 3288005

Browse files
christophstroblmp911de
authored andcommitted
Update native query documentation.
Closes #3636 Original pull request: #3637
1 parent 2757960 commit 3288005

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,26 @@ Valid values are (case-insensitive):
317317

318318
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.
319319

320+
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.
321+
The resulting map contains key/value pairs representing the actual database column name and the value.
322+
323+
.Native query retuning raw column name/value pairs
324+
====
325+
[source, java]
326+
----
327+
public interface UserRepository extends JpaRepository<User, Long> {
328+
329+
@NativeQuery("SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?1")
330+
Map<String, Object> findRawMapByEmail(String emailAddress); <1>
331+
332+
@NativeQuery("SELECT * FROM USERS WHERE LASTNAME = ?1")
333+
List<Map<String, Object>> findRawMapByLastname(String lastname); <2>
334+
}
335+
----
336+
<1> Single `Map` result backed by a `Tuple`.
337+
<2> Multiple `Map` results backed by ``Tuple``s.
338+
====
339+
320340
[[jpa.query-methods.sorting]]
321341
== Using Sort
322342

0 commit comments

Comments
 (0)