Reputation: 40337
Spring Data JPA constructs a number of queries based on naming convention of the interface methods. Is there any naming convention to do a "MEMBER OF" query?
I can get the following to work with JPQL:
@Query("select e from MyEntity e where ?1 member of e.entities")
However, I'd like to use a name convention method if possible. I couldn't find anything in the docs about it, so I'm hoping I'm just missing something. If there's some fundamental reason there can't be methods for this, I'd be interested to know that too.
Upvotes: 5
Views: 14443
Reputation: 852
The documentation seems to be incomplete about the Containing
(IsContaining
, Contains
) key word.
https://dzone.com/refcardz/core-spring-data extends the documentation as follows:
CONTAINING: Containing, IsContaining, Contains (String or collection types only)
So you are able to use the Containing
key word as a replacement for member of
.
For example:
// select e from MyEntity e where ?1 member of e.entities
findByEntitiesContaining(TypeOfMember member);
Upvotes: 1
Reputation: 385
Unfortunately, the answer provided by Zerlono didn't work for me.
However, I achieved the desired effect through the use of findDistinctBy and by emitting Containing
. Seems illogical, I know, but got the job done:
// select e from MyEntity e where ?1 member of e.entities
findDistinctByEntities(TypeOfMember member);
Upvotes: 1
Reputation: 310
Skimming the latest version of this document it doesn't look like there is. Here are the available method name keywords:
Upvotes: 2