Reputation: 2827
In my function I created a condition like this:
and (o.status != :shipped or (o.status = :cancelled and sp.cancelledQt != sp.requestedQt))
If I enable query logging this condition becomes:
and (shipmentor0_.status<>? or shipmentor0_.status=? and positions1_.cancelledQt<>positions1_.requestedQt)
As you can see the parenthesis are in a different order than I wrote.
What am I doing wrong?
Upvotes: 0
Views: 513
Reputation: 579
Nothing.
Hibernate it's just taking advantage of the distributive property of the logical disjunction (fancy name for "OR") to redact your query in a more efficient way.
It is one of the pros of using an ORM instead of plain JDBC.
Upvotes: 0
Reputation: 880
This is because the internal parenthesis is not necessary. The "And" operator precedence is higher then the "Or" operator. But you can keep it to make it more readable.
Upvotes: 1