Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Spring data JPA, how can I set the property expressions precedence?

I have this JPA query method:
findByZzzAndXxxOrYyy

which gives results for:
findBy(ZzzAndXxx)OrYyy // "And" gets higher precedence

Can I get results for?
findByZzzAnd(XxxOrYyy) // "Or" gets higher precedence

Guess I can do it with other query types (e.g. native)
but I wonder if I could just set the precedence by adding underscores or symbols or something...

like image 475
Gilad Shahrabani Avatar asked Nov 23 '15 15:11

Gilad Shahrabani


Video Answer


1 Answers

If I have understood it correctly, You would be writing a query, so you would have to make sure that whatever operation you want to perform first, should be included in parenthesis to get desired result.

E.g. I have table DEMO with Demo being the entity class with fields a,b and c. So per your requirement, the query would be:

Select * from Demo d where (d.a="SOME_VALUE" or d.b= "SOME_VALUE") and d.c="SOME_VALUE"

like image 119
Gourav Avatar answered Oct 18 '22 04:10

Gourav