membersound
membersound

Reputation: 86885

How to Query-By-Example with IN clause in spring-jpa?

I have a spring-jpa application and fetching rows from database with query-by-example like:

public List<Person> query() {
       Person p = new Person();
       person.name = "john";
       return dao.findAll(Example.of(p));
}

Problem: I want to add an IN clause, like: WHERE person.name IN ('john', 'jane');

Essentially, an IN clause is the same as an OR matching on a specific field.

So I could achieve the same with person.name = 'john' OR person.name = 'jane'.

BUT: how can I add those conditions into an example object that obviously has no list property?

Upvotes: 0

Views: 1270

Answers (1)

Jens Schauder
Jens Schauder

Reputation: 81988

As @Hitham S. AlQadheeb and @pirho hinted at, this is not supported by Query By Example. The documentation explicitly states:

Currently, only SingularAttribute properties can be used for property matching.

Use an alternative like Derived Queries, Specifications or a custom method implementation.

Upvotes: 2

Related Questions