From 80916d4b2539147839e1aaa253a5e96b701e5011 Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Wed, 7 Jun 2023 10:55:04 -0500 Subject: [PATCH] Add section to reference docs highlighting other possibilities. 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 --- src/main/asciidoc/jpa.adoc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/asciidoc/jpa.adoc b/src/main/asciidoc/jpa.adoc index 723989c40f..e8178c49df 100644 --- a/src/main/asciidoc/jpa.adoc +++ b/src/main/asciidoc/jpa.adoc @@ -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 <>. +* If that doesn't fit your needs, consider implementing a <>. 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 <> or if it's a database function using the <> 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