Reputation: 510
The complex WHERE query with OR condition is not translated correctly to native query
JPQL query condition:
WHERE i.id = :id AND ( (i.group = 1 ) OR (i.group != 1 and i.orderDate > :todaysDate))
is being translated as
where item.id=?
and (
item.group=1
or item.group<>1
and item.due_date>?
)
We can observe that the second condition of AND is not being evaluated in correct order. How to deal with complex where queries in JPQL
Instead i believe it should ideally would have been
where item.id=?
and (
item.group=1
or
(item.group<>1
and item.due_date>?)
)
Upvotes: 0
Views: 82
Reputation: 8206
The AND
operator is evaluated before the OR
operator when there are no round brackets.
Unless you are saying that this is not the case in the database you are using, there is no difference between the two queries.
Upvotes: 1