Skip to content

Commit

Permalink
Add section to reference docs highlighting other possibilities.
Browse files Browse the repository at this point in the history
Give users that have too complex of a query a list of where to go should Spring Data JPA not offer what they need in query support.

See #3005
Original Pull Request: #3006
  • Loading branch information
gregturn committed Jun 8, 2023
1 parent 2e489cb commit 80916d4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/asciidoc/jpa.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,22 @@ The escape character used can be configured by setting the `escapeCharacter` of
Note that the method `escape(String)` available in the SpEL context will only escape the SQL and JPQL standard wildcards `_` and `%`.
If the underlying database or the JPA implementation supports additional wildcards these will not get escaped.

[[jpa.query.other-methods]]
=== Other Methods

Spring Data JPA offers many ways to build queries.
But sometimes, your query may simply be too complicated for the techniques offered.
In that situation, consider:

* If you haven't already, simply write the query yourself using <<jpa.query-methods.at-query,`@Query`>>.
* If that doesn't fit your needs, consider implementing a <<repositories.custom-implementations,custom implementation>>. This lets you register a method in your repository while leaving the implementation completely up to you. This gives you the ability to:
** Talk directly to the `EntityManager` (writing pure HQL/JPQL/EQL/native SQL or using the *Criteria API*)
** Leverage Spring Framework's `JdbcTemplate` (native SQL)
** Use another 3rd-party database toolkit.
* Another option is putting your query inside the database and then using either Spring Data JPA's <<jpa.stored-procedures,`@StoredProcedure` annotation>> or if it's a database function using the <<jpa.query-methods.at-query,`@Query` annotation>> and invoking it with a `CALL`.

These tactics may be most effective when you need maximum control of your query, while still letting Spring Data JPA provide resource management.

[[jpa.modifying-queries]]
=== Modifying Queries

Expand Down

0 comments on commit 80916d4

Please sign in to comment.