JPA - native queries
Table of Contents
Native queries using jpa
We can write SQL native queries in Spring Boot applications with @Query
annotation.
- define SQL in the value attribute
- set the nativeQuery attribute value to true
Note that:
-
Spring Data JPA don’t adjust the query to database’s specific SQL dialect, so ensure that the provided statement is supported by RDBMS.
-
Spring Data JPA does not currently support dynamic sorting for native queries, because it would have to manipulate the actual query declared, which it cannot do reliably for native SQL.
How to make the query ignore the optional parameters?