Skip to content

Commit eece4cf

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

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
@@ -318,6 +318,26 @@ Valid values are (case-insensitive):
318318

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

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

0 commit comments

Comments
 (0)