Skip to content

Commit

Permalink
Update native query documentation.
Browse files Browse the repository at this point in the history
Closes #3636
Original pull request: #3637
  • Loading branch information
christophstrobl authored and mp911de committed Oct 17, 2024
1 parent d6b928e commit d74decc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/antora/modules/ROOT/pages/jpa/query-methods.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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<User, Long> {
@NativeQuery("SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?1")
Map<String, Object> findRawMapByEmail(String emailAddress); <1>
@NativeQuery("SELECT * FROM USERS WHERE LASTNAME = ?1")
List<Map<String, Object>> 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

Expand Down

0 comments on commit d74decc

Please # to comment.