6

As per Spring Docs, I can write exact matching only for QBE. I need exact matching only but among a set of values (IN clause of query).

e.g.

Person p = new Person();
p.setId(); // need to match among set of ids.
Example.of(p);

Is this somehow achievable with QBE or am I totally down the wrong path?

Something like :

Page<S> findByIdIn(List<Integer> ids, Example<S> e, Pageable p)

best of both worlds?

What I really need, dynamic query based on multiple fields (in possible combinations, say id in (1,2,4), status=open, appointmentDate < today) along with pagination and sorting. Is specification the only way to go apart from native query?

Sachin Sharma
  • 1,446
  • 4
  • 18
  • 37

1 Answers1

7

I need exact matching only but among a set of values (IN clause of query).

So you need something other than exact matching. You can't possibly store a set of IDs in the ID property of your Person. QBE is clearly not the right tool for the job.

You can use Specifications, the Criteria API directly, QueryDSL, a dynamically composed JPQL query, or whatever other solution, but not QBE.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • was hoping for something like: Page findByIdIn(List ids, Example e, Pageable p) – Sachin Sharma Jan 30 '18 at 18:39
  • [Spring Data documentation](https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#query-by-example.matchers) - non string values are not allowed for matching (only exact matching) – Bogdan Oros Jan 30 '18 at 18:44
  • I'll be writing specifications then. – Sachin Sharma Jan 30 '18 at 18:45
  • 3
    You can transform an Example into a Predicate that you can then combine with other predicates using https://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/convert/QueryByExamplePredicateBuilder.html – JB Nizet Jan 30 '18 at 18:48